/// <summary>
        /// Creates a new dictionary.
        /// </summary>
        /// <param name="file">A memory mapped file.</param>
        /// <param name="readKeyFrom"></param>
        /// <param name="writeToKey"></param>
        /// <param name="readValueFrom"></param>
        /// <param name="writeValueTo"></param>
        /// <param name="hashKey"></param>
        /// <param name="compareKey"></param>
        public MemoryMappedHugeDictionary(MemoryMappedFile file,
                                          MemoryMappedFile.ReadFromDelegate <TKey> readKeyFrom, MemoryMappedFile.WriteToDelegate <TKey> writeToKey,
                                          MemoryMappedFile.ReadFromDelegate <TValue> readValueFrom, MemoryMappedFile.WriteToDelegate <TValue> writeValueTo,
                                          Func <TKey, int> hashKey, Func <TKey, TKey, int> compareKey)
        {
            _file       = file;
            _size       = 0;
            _nextPairId = 0;
            _hashKey    = hashKey;
            _compareKey = compareKey;

            _hashes = new MemoryMappedHugeArrayInt64(_file, 1024 * 1024,
                                                     MemoryMappedHugeArrayInt64.DefaultFileElementSize,
                                                     (int)MemoryMappedHugeArrayInt64.DefaultFileElementSize / MemoryMappedHugeArrayInt64.DefaultBufferSize,
                                                     MemoryMappedHugeArrayInt64.DefaultCacheSize);
            for (int idx = 0; idx < _hashes.Length; idx++)
            {
                _hashes[idx] = -1;
            }
            _pairs = new MemoryMappedHugeArrayInt64(_file, 16 * 4);
            _keys  = new MemoryMappedIndex <KeyStruct>(_file,
                                                       (stream, position) =>
            {
                return(new KeyStruct()
                {
                    Key = readKeyFrom.Invoke(stream, position)
                });
            },
                                                       (stream, position, structure) =>
            {
                return(writeToKey.Invoke(stream, position, structure.Key));
            });
            _values = new MemoryMappedIndex <ValueStruct>(_file,
                                                          (stream, position) =>
            {
                return(new ValueStruct()
                {
                    Value = readValueFrom.Invoke(stream, position)
                });
            },
                                                          (stream, position, structure) =>
            {
                return(writeValueTo.Invoke(stream, position, structure.Value));
            });
        }
 /// <summary>
 /// Writes the structure at the given position.
 /// </summary>
 /// <param name="position"></param>
 /// <param name="structure"></param>
 /// <returns></returns>
 public sealed override long Write(long position, ref T structure)
 {
     return(_writeTo.Invoke(_stream, position, structure));
 }