diff options
author | Linus Nordberg <linus@nordu.net> | 2016-05-09 13:13:29 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2016-05-09 13:13:29 +0200 |
commit | db6acff457a68e8a645594687b789c6cb13b4f49 (patch) | |
tree | 87cb826e908ac93e3d35211ec38c2ad121a35ca6 /c_src/permdb.c | |
parent | 8cb49bd7170991493cbb12a5a1231f4332c43624 (diff) |
Document keybits() and make it slightly easier to read.
Also, remove unused KEYPART_MAX.
Diffstat (limited to 'c_src/permdb.c')
-rw-r--r-- | c_src/permdb.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/c_src/permdb.c b/c_src/permdb.c index f740dd8..604899b 100644 --- a/c_src/permdb.c +++ b/c_src/permdb.c @@ -484,16 +484,22 @@ permdb_free(permdb_object *state) } +/* + * Returns the two bits of KEY that are used for LEVEL, for a q=2 + * tree. + */ static unsigned char keybits(const unsigned char *key, unsigned int level) { + /* Finding the proper octet in key. */ unsigned char b = key[level/4]; + /* "Micro-level", for finding the proper two bits, below. */ + unsigned int mlev = level % 4; - return (b >> (6-(level*2) % 8)) & 0x3; + /* Shift right and mask off the two lowest bits. */ + return (b >> (6 - 2*mlev)) & 0x3; } -#define KEYPART_MAX (keylen*4+1) - static void keypart(const unsigned char *key, unsigned int level, ps_string *s) { |