Paste: clay stuff

Author: pruned
Mode: c++
Date: Sat, 4 Dec 2010 12:04:46
Plain Text |
[E, K]
allocateEntryAt(th: TwoHash[E], key: K, rvalue entry: E)
{
    assert(null?(pEntryAt(th, key)));
    
    var hash = splitHash(th, key);
    var entryCount = [0,0];
    for (i in range(2))
    {
        for (k in range(16))
        {
            if (th.tables[i][hash[i]].hashBytes[k] != 255)
                entryCount[i] += 1;
        }
    }
    
    if (min(entryCount[0], entryCount[1]) == 16)
    {
        grow(th);
        return allocateEntryAt(th, key, entry);
    }
    
    var bi = 0;
    if (entryCount[1] < entryCount[0])
        bi = 1;
        
    for (k in range(16))
    {
        if (th.tables[bi][hash[bi]].hashBytes[k] == 255)
        {
            th.tables[bi][hash[bi]].hashBytes[k] = Byte(hash[2]);
            var pEntry = &th.tables[bi][hash[bi]].entries[k];
            pEntry^ <-- move(entry);
            return pEntry;
        }
    }
    
    assert(false, "shouldn't reach");
    return null(E);
}

New Annotation

Summary:
Author:
Mode:
Body: