tamarin之inlinehashtable

来源:互联网 发布:越南viettel 网络类型 编辑:程序博客网 时间:2024/06/05 01:56
// ------------------------ DATA SECTION BEGIN
    private:指向atom数组,该数组是atom指针。
        uintptr_t m_atomsAndFlags;    /** property hashtable, this has no DWB on purpose, setAtoms contains the WB */
    #ifdef AVMPLUS_64BIT
        // on 64-bit systems, padding will force us to 16 bytes here anyway, so let's just use unpacked ints
        uint32_t m_size;            // number of properties
        uint32_t m_logCapacity;        // (log2 of capacity) + 1
    #else
        uint32_t m_size:27;            // number of properties
        uint32_t m_logCapacity:5;    // (log2 of capacity) + 1 -- gives us enough space for 2^32 entries
    #endif

    // ------------------------ DATA SECTION END

在32位系统下,inlinehashtable只占用8byte。

static inline uint32_t FindOneBit(uint32_t value)中用到了

_BitScanReverse()

Microsoft Specific

Search the mask data from most significant bit (MSB) to least significant bit (LSB) for a set bit (1).

从最高位到最低位查找mask的1,也就是查找值为1的最高位
unsigned char _BitScanReverse(   unsigned long * Index,   unsigned long Mask);unsigned char _BitScanReverse64(   unsigned long * Index,   unsigned __int64 Mask);void InlineHashtable::put(Atom name, Atom value)    {        Atom* atoms = getAtoms();        int i = find(name, atoms, getCapacity());获取hashtable的容量,1UL<<(m_logCapacity-1)        GC *gc = GC::GetGC(atoms);        if (removeDontEnumMask(atoms[i]) != name) {            AvmAssert(!isFull());                        //atoms[i] = name;            WBATOM(gc, atoms, &atoms[i], name);            m_size++;        }        //atoms[i+1] = value;        WBATOM( gc, atoms, &atoms[i+1], value);    }int InlineHashtable::find(Atom x, const Atom *t, uint32_t m) const    {        uintptr_t mask = ~(m_atomsAndFlags & kDontEnumBit(0x1));        x &= mask;                #if 0 // debug code to print out the strings we're searching for        static int debug =0;        if (debug && AvmCore::isString(x))        {            Stringp s = AvmCore::atomToString(x);            AvmDebugMsg (s->c_str(), false);            AvmDebugMsg ("\n", false);        }        #endif        uintptr_t bitmask = (m - 1) & ~0x1;        AvmAssert(x != EMPTY && x != DELETED);        // this is a quadratic probe but we only hit even numbered slots since those hold keys.        int n = 7 << 1;        #ifdef _DEBUG        uint32_t loopCount = 0;        #endif        // Note: Mask off MSB to avoid negative indices.  Mask off bottom        // 3 bits because it doesn't contribute to hash.  Double it        // because names, values stored adjacently.        uint32_t i = ((0x7FFFFFF8 & x)>>2) & bitmask;          Atom k;        while ((k=t[i]&mask) != x && k != EMPTY)        {            i = (i + (n += 2)) & bitmask;        // quadratic probe            AvmAssert(loopCount++ < m);            // don't scan forever        }        AvmAssert(i <= ((m-1)&~0x1));        return i;    }Atom removeDontEnumMask(Atom a) const { return Atom(uintptr_t(a) & ~(m_atomsAndFlags & kDontEnumBit)); }清除原子的不用枚举标志对于名值对,
//atoms[i+1] = value;WBATOM( gc, atoms, &atoms[i+1], value);
???如何解决冲突