コード例 #1
0
ファイル: Heaps.cs プロジェクト: djbhau/TraceLab
        internal int Add(ByteBuffer bb)
        {
            Debug.Assert(!frozen);
            int bblen = bb.Length;

            if (bblen == 0)
            {
                return(0);
            }
            int lenlen = MetadataWriter.GetCompressedIntLength(bblen);
            int hash   = bb.Hash();
            int index  = (hash & 0x7FFFFFFF) % map.Length;

            Key[] keys = map;
            int   last = index;

            while (keys[index].offset != 0)
            {
                if (keys[index].hash == hash &&
                    keys[index].len == bblen &&
                    buf.Match(keys[index].offset + lenlen, bb, 0, bblen))
                {
                    return(keys[index].offset);
                }
                if (index == last)
                {
                    if (keys[index].next == null)
                    {
                        keys[index].next = new Key[4];
                        keys             = keys[index].next;
                        index            = 0;
                        break;
                    }
                    keys  = keys[index].next;
                    index = -1;
                    last  = keys.Length - 1;
                }
                index++;
            }
            int offset = buf.Position;

            buf.WriteCompressedInt(bblen);
            buf.Write(bb);
            keys[index].len    = bblen;
            keys[index].hash   = hash;
            keys[index].offset = offset;
            return(offset);
        }