public void PutEntries(List <BufferEntry> entries)
        {
            int size = CalculateEntriesSize(entries) * 2;

            this.buffer = new MemoryStreamWrapper(new MemoryStream(size + Constant.INTEGER_BYTES * 4));

            buffer.WriteInt32(size);
            buffer.WriteInt32(entries.Count);
            BufferEntry firstEntry = entries[0];

            buffer.WriteInt32(firstEntry.TokenInfo.Count);
            buffer.WriteInt32(firstEntry.PosInfo.Count);
            buffer.WriteInt32(firstEntry.Features.Count);

            foreach (BufferEntry entry in entries)
            {
                foreach (short s in entry.TokenInfo)
                {
                    buffer.WriteInt16(s);
                }

                buffer.Write(entry.PosInfo.ToArray(), 0, entry.PosInfo.Count);

                foreach (int feature in entry.Features)
                {
                    buffer.WriteInt32(feature);
                }
            }
        }
Exemplo n.º 2
0
        private void Put(SortedDictionary <int, string> strings)
        {
            int bufferSize = CalculateSize(strings);

            size = strings.Count;

            if (buffer != null)
            {
                buffer.Dispose();
            }

            buffer = new MemoryStreamWrapper(new MemoryStream(bufferSize));
            buffer.WriteInt32(size);                 // Set entries

            int keyIndex   = Constant.INTEGER_BYTES; // First key index is past size
            int entryIndex = keyIndex + size * Constant.INTEGER_BYTES;

            foreach (string str in strings.Values)
            {
                buffer.WriteInt32(entryIndex, keyIndex);
                entryIndex = Put(entryIndex, str);
                keyIndex  += Constant.INTEGER_BYTES;
            }
        }