/// <summary> /// Add a given item to the index for a given word. /// </summary> /// <param name="id">Item to add</param> /// <param name="word">Word with which to associate item</param> public void AddWord(ushort id, ByteBlock word) { WordIndexBlock block = null; ushort wordIndex = ushort.MaxValue; // If the word is already in a block, get the index for (int i = 0; i < _blocks.Count; ++i) { block = _blocks[i]; wordIndex = block.IndexOf(word); if (wordIndex != ushort.MaxValue) { break; } } // If not, try to add the word to the last block if (wordIndex == ushort.MaxValue && block != null) { wordIndex = block.Add(word); } // If the last block was full, add another block if (wordIndex == ushort.MaxValue) { block = new WordIndexBlock(); wordIndex = block.Add(word); _blocks.Add(block); } block.AddToSet(wordIndex, id); }
public void ReadBinary(ISerializationContext context) { if (context == null) { throw new ArgumentNullException("context"); } _blocks.Clear(); int blockCount = context.Reader.ReadInt32(); for (int i = 0; i < blockCount; ++i) { WordIndexBlock block = new WordIndexBlock(); block.ReadBinary(context); _blocks.Add(block); } }