Ejemplo n.º 1
0
        internal int Add(ByteBuffer bb)
        {
            Debug.Assert(!frozen);
            int bblen = bb.Length;

            if (bblen == 0)
            {
                return(0);
            }
            int lenlen = MetadataWriter.GetCompressedUIntLength(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.WriteCompressedUInt(bblen);
            buf.Write(bb);
            keys[index].len    = bblen;
            keys[index].hash   = hash;
            keys[index].offset = offset;
            return(offset);
        }
Ejemplo n.º 2
0
        internal int Add(string str)
        {
            Debug.Assert(!frozen);
            int offset;

            if (!strings.TryGetValue(str, out offset))
            {
                int length = str.Length * 2 + 1 + MetadataWriter.GetCompressedUIntLength(str.Length * 2 + 1);
                if (nextOffset + length > 0xFFFFFF)
                {
                    throw new FileFormatLimitationExceededException("No logical space left to create more user strings.", FileFormatLimitationExceededException.META_E_STRINGSPACE_FULL);
                }
                offset      = nextOffset;
                nextOffset += length;
                list.Add(str);
                strings.Add(str, offset);
            }
            return(offset);
        }