Exemplo n.º 1
0
        // Adds a value by key, optionally saves index
        public void Add(K key, V value, bool saveOnWrite = false)
        {
            if (_indices.ContainsKey(key))
            {
                throw new ArgumentException($"The key: {key} already has been added.");
            }

            _fs.Seek(0, SeekOrigin.End);
            var offset = (uint)_fs.Position;

            using (var bw = new BinaryWriter(_fs, Encoding.UTF8, true))
            {
                uint valueLength = WriteParts(bw, value);
                _indices.AddIndex(offset, valueLength, key);
            }

            if (saveOnWrite)
            {
                _indices.Save();
                _fs.Flush();
            }
        }
Exemplo n.º 2
0
 public bool ContainsKey(K key)
 {
     return(_indices.ContainsKey(key));
 }