]> mj.ucw.cz Git - libucw.git/commitdiff
Varints: Added documentation.
authorTomas Valla <tom@ucw.cz>
Thu, 28 Mar 2013 13:12:23 +0000 (14:12 +0100)
committerTomas Valla <tom@ucw.cz>
Thu, 28 Mar 2013 13:12:23 +0000 (14:12 +0100)
ucw/doc/Makefile
ucw/doc/index.txt
ucw/doc/varint.txt [new file with mode: 0644]
ucw/varint.h

index 4da7cf8c49068e63ca542068db2b14aef6edaf59..7a018f3d3997fc5c2c9a936c45ec1fc9392f1598 100644 (file)
@@ -2,7 +2,7 @@
 
 DIRS+=ucw/doc
 
-UCW_DOCS=basics log fastbuf index config configure install basecode hash docsys conf mempool eltpool mainloop generic growbuf unaligned lists chartype unicode prime binsearch heap binheap compress sort hashtable relnotes trans string time daemon signal
+UCW_DOCS=basics log fastbuf index config configure install basecode hash docsys conf mempool eltpool mainloop generic growbuf unaligned lists chartype unicode prime binsearch heap binheap compress sort hashtable relnotes trans string time daemon signal varint
 UCW_INDEX=$(o)/ucw/doc/def_index.html
 UCW_DOCS_HTML=$(addprefix $(o)/ucw/doc/,$(addsuffix .html,$(UCW_DOCS)))
 
index e449c755064ed77628f893a27488887217ca5e24..f82400687cf6bd2cb7f861613e672b7b567259a1 100644 (file)
@@ -33,6 +33,7 @@ Modules
 - <<growbuf:,Growing buffers>>
 - <<chartype:,Single-byte characters>>
 - <<unicode:,Multi-byte characters>>
+- <<varint:,Encoding of integers>>
 - <<prime:,Prime numbers>>
 - <<sort:,Sorting>>
 - <<binsearch:,Binary search>>
diff --git a/ucw/doc/varint.txt b/ucw/doc/varint.txt
new file mode 100644 (file)
index 0000000..85687bf
--- /dev/null
@@ -0,0 +1,4 @@
+Efficient encoding of u64 to byte sequence
+==========================================
+
+!!ucw/varint.h
index 79952dc143eb76dd02c582397ef8b070a4bb4007..2688a088819694a52baf052d1894b2c831339eef 100644 (file)
 /***
  * The encoding works in the following way:
  *
- * First byte                  Stored values
+ *  First byte                 Stored values
  *
- * 0xxxxxxx                    7 bits
- * 10xxxxxx  +1 byte           14 bits, value shifted by 2^7
- * 110xxxxx  +2 bytes          21 bits, value shifted by 2^7+2^14
- * 1110xxxx  +3 bytes          28 bits, value shifted by 2^7+2^14+2^21
+ *  0xxxxxxx                   7 bits
+ *  10xxxxxx  +1 byte          14 bits, value shifted by 2^7
+ *  110xxxxx  +2 bytes         21 bits, value shifted by 2^7+2^14
+ *  1110xxxx  +3 bytes         28 bits, value shifted by 2^7+2^14+2^21
  *    ....
- * 11111110  +7 bytes          56 bits, value shifted by 2^7+2^14+2^21+2^28+2^35+2^42
- * 11111111  +8 bytes          full 64 bits, value shifted by 2^7+2^14+2^21+2^28+2^35+2^42+2^56
+ *  11111110  +7 bytes         56 bits, value shifted by 2^7+2^14+2^21+2^28+2^35+2^42
+ *  11111111  +8 bytes         full 64 bits, value shifted by 2^7+2^14+2^21+2^28+2^35+2^42+2^56
  *
  * The values are stored in bigendian to allow lexicographic sorting.
  * The encoding and algorithms are aimed to be optimised for storing shorter numbers.