Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ahtable uses msb or lsb for two-byte length indicator? #21

Open
canadaduane opened this issue Sep 19, 2014 · 5 comments
Open

ahtable uses msb or lsb for two-byte length indicator? #21

canadaduane opened this issue Sep 19, 2014 · 5 comments

Comments

@canadaduane
Copy link
Contributor

I was puzzling over the code this morning and came across this comment:

        /* The most significant bit is set to indicate that two bytes are
         * being used to store the key length. */
        *((uint16_t*) s) = ((uint16_t) len << 1) | 0x1;
        s += 2;

It seems like that is the least significant bit being set, not the most significant, right? If I understand the Intel convention, the LSB (least significant byte) is then packed into the smaller memory address, so the 0x1 will be in the first byte of the 2-byte word. (Just doing a verbal sanity check :)

@canadaduane
Copy link
Contributor Author

BTW, how is this for a summary of ahtable?

/*
 * ahtable : an array hash table
 *
 * ahtable keeps a dynamically sized array of variable-length keys and
 * fixed-length values. A key/value pair is stored in a "slot". The first
 * byte of each slot indicates the length of the key, UNLESS the least
 * significant bit of the first byte is set, in which case the first TWO
 * bytes of the slot indicate the length of the key (allowing for keys longer
 * than 127 bytes).
 *
 */

@canadaduane
Copy link
Contributor Author

I see I'm missing the whole hash aspect of this. Need to mention pre-allocated fixed number of slots and the use of hashing to get to the correct slot number. Also, I must have misunderstood the one key/value pair per slot bit.

@canadaduane
Copy link
Contributor Author

Ahh, finally found a free version of the paper. http://naskitis.com/naskitis-spire05.pdf

@dcjones
Copy link
Owner

dcjones commented Sep 20, 2014

Judging from your pull request, you figured this out already?

@canadaduane
Copy link
Contributor Author

Yes, but I don't work on C code very often, so it was more a confidence
check than anything.
On Sep 20, 2014 3:08 PM, "Daniel Jones" notifications@github.com wrote:

Judging from your pull request, you figured this out already?


Reply to this email directly or view it on GitHub
#21 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants