コード例 #1
0
        /// <summary>
        /// Creates a new index.
        /// </summary>
        public AttributesIndex(MemoryMap map,
                               AttributesIndexMode mode = AttributesIndexMode.ReverseCollectionIndex |
                               AttributesIndexMode.ReverseStringIndex)
        {
            if (mode == AttributesIndexMode.None)
            {
                throw new ArgumentException("Cannot create a new index without a valid operating mode.");
            }

            _stringIndex            = new Index <string>(map);
            _collectionIndex        = new Index <int[]>(map);
            _isReadonly             = false;
            _mode                   = mode;
            _stringReverseIndex     = null;
            _collectionReverseIndex = null;

            if ((_mode & AttributesIndexMode.IncreaseOne) == AttributesIndexMode.IncreaseOne)
            { // create the increment-by-one data structures.
                _index  = new Array <uint>(map, 1024);
                _nextId = 0;
            }

            if ((_mode & AttributesIndexMode.ReverseStringIndex) == AttributesIndexMode.ReverseStringIndex ||
                (_mode & AttributesIndexMode.ReverseStringIndexKeysOnly) == AttributesIndexMode.ReverseStringIndexKeysOnly)
            {
                _stringReverseIndex = new Reminiscence.Collections.Dictionary <string, int>(map, 1024 * 16);
            }
            if ((_mode & AttributesIndexMode.ReverseCollectionIndex) == AttributesIndexMode.ReverseCollectionIndex)
            {
                _collectionReverseIndex = new Reminiscence.Collections.Dictionary <int[], uint>(map, 1024 * 16, new EqualityComparer());
            }
        }
コード例 #2
0
ファイル: AttributesIndex.cs プロジェクト: amseet/Orion
        /// <summary>
        /// Deserializes a tags index from the given stream.
        /// </summary>
        public static AttributesIndex Deserialize(System.IO.Stream stream, bool copy   = false,
                                                  AttributesIndexMode defaultIndexMode = AttributesIndexMode.ReverseStringIndexKeysOnly)
        {
            // read version byte.
            long position = 1;
            var  version  = stream.ReadByte();

            int type = 0;

            if (version < 2)
            { // unversioned version.
                type = (byte)version;
            }
            else
            { // versioned.
                // read the index mode.
                var indexModeByte = stream.ReadByte();
                position++;
                defaultIndexMode = (AttributesIndexMode)indexModeByte;

                // read the type.
                type = stream.ReadByte();
                position++;
            }

            // read the actual data.
            long size;

            if (type == 0)
            { // regular index.
                var tagsIndex = Index <int[]> .CreateFromWithSize(stream, out size, !copy);

                position += size + 8;
                stream.Seek(position, System.IO.SeekOrigin.Begin);
                var limitedStream = new LimitedStream(stream);
                var stringIndex   = Index <string> .CreateFromWithSize(limitedStream, out size, !copy);

                position += size + 8;
                stream.Seek(position, System.IO.SeekOrigin.Begin);
                return(new AttributesIndex(defaultIndexMode, stringIndex, tagsIndex));
            }
            else
            { // increase one index.
                var tagsIndex = Index <int[]> .CreateFromWithSize(stream, out size, !copy);

                position += size + 8;
                stream.Seek(position, System.IO.SeekOrigin.Begin);
                var limitedStream = new LimitedStream(stream);
                var stringIndex   = Index <string> .CreateFromWithSize(limitedStream, out size, !copy);

                position += size + 8;
                stream.Seek(position, System.IO.SeekOrigin.Begin);
                var indexLengthBytes = new byte[8];
                stream.Read(indexLengthBytes, 0, 8);
                var indexLength = BitConverter.ToInt64(indexLengthBytes, 0);
                var index       = Context.ArrayFactory.CreateMemoryBackedArray <uint>(indexLength);
                index.CopyFrom(stream);
                return(new AttributesIndex(defaultIndexMode, stringIndex, tagsIndex, index));
            }
        }
コード例 #3
0
        private System.Collections.Generic.IDictionary <int[], uint> _collectionReverseIndex; // Holds all tag collections and their reverse index.

        /// <summary>
        /// Creates a new empty index.
        /// </summary>
        public AttributesIndex(AttributesIndexMode mode = AttributesIndexMode.ReverseCollectionIndex |
                               AttributesIndexMode.ReverseStringIndex)
        {
            _stringIndex            = new Index <string>();
            _collectionIndex        = new Index <int[]>();
            _isReadonly             = false;
            _mode                   = mode;
            _stringReverseIndex     = null;
            _collectionReverseIndex = null;

            if ((_mode & AttributesIndexMode.IncreaseOne) == AttributesIndexMode.IncreaseOne)
            {
                _index  = new MemoryArray <uint>(1024);
                _nextId = 0;
            }

            if ((_mode & AttributesIndexMode.ReverseStringIndex) == AttributesIndexMode.ReverseStringIndex ||
                (_mode & AttributesIndexMode.ReverseStringIndexKeysOnly) == AttributesIndexMode.ReverseStringIndexKeysOnly)
            {
                _stringReverseIndex = new System.Collections.Generic.Dictionary <string, int>();
            }
            if ((_mode & AttributesIndexMode.ReverseCollectionIndex) == AttributesIndexMode.ReverseCollectionIndex)
            {
                _collectionReverseIndex = new System.Collections.Generic.Dictionary <int[], uint>(new EqualityComparer());
            }
        }
コード例 #4
0
ファイル: AttributesIndex.cs プロジェクト: amseet/Orion
        /// <summary>
        /// Creates a new index.
        /// </summary>
        public AttributesIndex(MemoryMap map,
                               AttributesIndexMode mode = AttributesIndexMode.ReverseCollectionIndex |
                               AttributesIndexMode.ReverseStringIndex)
        {
            if (mode == AttributesIndexMode.None)
            {
                throw new ArgumentException("Cannot create a new index without a valid operating mode.");
            }

            _stringIndex            = new Index <string>(map);
            _collectionIndex        = new Index <int[]>(map);
            _isReadonly             = false;
            _mode                   = mode;
            _stringReverseIndex     = null;
            _collectionReverseIndex = null;

            if ((_mode & AttributesIndexMode.IncreaseOne) == AttributesIndexMode.IncreaseOne)
            { // create the increment-by-one data structures.
                _index  = new Array <uint>(map, 1024);
                _nextId = 0;
            }

            if ((_mode & AttributesIndexMode.ReverseStringIndex) == AttributesIndexMode.ReverseStringIndex ||
                (_mode & AttributesIndexMode.ReverseStringIndexKeysOnly) == AttributesIndexMode.ReverseStringIndexKeysOnly)
            {
                _stringReverseIndex = new Reminiscence.Collections.Dictionary <string, int>(map, 1024 * 16);
            }
            if ((_mode & AttributesIndexMode.ReverseCollectionIndex) == AttributesIndexMode.ReverseCollectionIndex)
            {
                _collectionReverseIndex = new Reminiscence.Collections.Dictionary <int[], uint>(map, 1024 * 16,
                                                                                                new DelegateEqualityComparer <int[]>(
                                                                                                    (obj) =>
                {         // assumed the array is sorted.
                    var hash = obj.Length.GetHashCode();
                    for (int idx = 0; idx < obj.Length; idx++)
                    {
                        hash = hash ^ obj[idx].GetHashCode();
                    }
                    return(hash);
                },
                                                                                                    (x, y) =>
                {
                    if (x.Length == y.Length)
                    {
                        for (int idx = 0; idx < x.Length; idx++)
                        {
                            if (x[idx] != y[idx])
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                    return(false);
                }));
            }
        }
コード例 #5
0
        public AttributesIndex(MemoryMap map, AttributesIndexMode mode = AttributesIndexMode.ReverseAll)
        {
            if (mode == AttributesIndexMode.None)
            {
                throw new ArgumentException("Cannot create a new index without a valid operating mode.");
            }
            this._stringIndex            = new Index <string>(map);
            this._collectionIndex        = new Index <int[]>(map);
            this._isReadonly             = false;
            this._mode                   = mode;
            this._stringReverseIndex     = (IDictionary <string, int>)null;
            this._collectionReverseIndex = (IDictionary <int[], uint>)null;
            if ((this._mode & AttributesIndexMode.IncreaseOne) == AttributesIndexMode.IncreaseOne)
            {
                this._index  = (ArrayBase <uint>) new Array <uint>(map, 1024L);
                this._nextId = 0U;
            }
            if ((this._mode & AttributesIndexMode.ReverseStringIndex) == AttributesIndexMode.ReverseStringIndex || (this._mode & AttributesIndexMode.ReverseStringIndexKeysOnly) == AttributesIndexMode.ReverseStringIndexKeysOnly)
            {
                this._stringReverseIndex = (IDictionary <string, int>) new Reminiscence.Collections.Dictionary <string, int>(map, 16384);
            }
            if ((this._mode & AttributesIndexMode.ReverseCollectionIndex) != AttributesIndexMode.ReverseCollectionIndex)
            {
                return;
            }
            MemoryMap memoryMap = map;
            int       num       = 16384;

            DelegateEqualityComparer <int[]> .GetHashCodeDelegate hashCodeDelegate1 = (DelegateEqualityComparer <int[]> .GetHashCodeDelegate)(obj =>
            {
                int hashCode = obj.Length.GetHashCode();
                for (int index = 0; index < obj.Length; ++index)
                {
                    hashCode ^= obj[index].GetHashCode();
                }
                return(hashCode);
            });
            DelegateEqualityComparer <int[]> equalityComparer = new DelegateEqualityComparer <int[]>(hashCodeDelegate1, (DelegateEqualityComparer <int[]> .EqualsDelegate)((x, y) =>
            {
                if (x.Length != y.Length)
                {
                    return(false);
                }
                for (int index = 0; index < x.Length; ++index)
                {
                    if (x[index] != y[index])
                    {
                        return(false);
                    }
                }
                return(true);
            }));

            this._collectionReverseIndex = (IDictionary <int[], uint>) new Reminiscence.Collections.Dictionary <int[], uint>(memoryMap, num, (IEqualityComparer <int[]>)equalityComparer);
        }
コード例 #6
0
 internal AttributesIndex(Index <string> stringIndex, Index <int[]> tagsIndex, ArrayBase <uint> index)
 {
     this._stringIndex            = stringIndex;
     this._collectionIndex        = tagsIndex;
     this._isReadonly             = true;
     this._index                  = index;
     this._nextId                 = (uint)index.Length;
     this._mode                   = AttributesIndexMode.None;
     this._stringReverseIndex     = (IDictionary <string, int>)null;
     this._collectionReverseIndex = (IDictionary <int[], uint>)null;
 }
コード例 #7
0
ファイル: MappedAttributesIndex.cs プロジェクト: amseet/Orion
        /// <summary>
        /// Creates a new mapped attributes index.
        /// </summary>
        public MappedAttributesIndex(AttributesIndexMode mode = AttributesIndexMode.ReverseCollectionIndex |
                                     AttributesIndexMode.ReverseStringIndex)
        {
            _data         = new MemoryArray <uint>(1024);
            _attributes   = new AttributesIndex(mode);
            _reverseIndex = new HugeDictionary <uint, int>();

            for (var p = 0; p < _data.Length; p++)
            {
                _data[p] = _NO_DATA;
            }
        }
コード例 #8
0
ファイル: AttributesIndex.cs プロジェクト: amseet/Orion
        /// <summary>
        /// Creates a new index.
        /// </summary>
        internal AttributesIndex(AttributesIndexMode mode, Index <string> stringIndex, Index <int[]> tagsIndex, ArrayBase <uint> index)
        {
            _stringIndex     = stringIndex;
            _collectionIndex = tagsIndex;
            _isReadonly      = true;
            _index           = index;
            _nextId          = (uint)index.Length;
            _mode            = mode;

            _stringReverseIndex     = null;
            _collectionReverseIndex = null;
        }
コード例 #9
0
ファイル: AttributesIndex.cs プロジェクト: amseet/Orion
        /// <summary>
        /// Creates a new index.
        /// </summary>
        internal AttributesIndex(AttributesIndexMode mode, Index <string> stringIndex, Index <int[]> tagsIndex)
        {
            _stringIndex     = stringIndex;
            _collectionIndex = tagsIndex;
            _isReadonly      = true;
            _index           = null;
            _nextId          = uint.MaxValue;
            _mode            = mode;

            _stringReverseIndex     = null;
            _collectionReverseIndex = null;
        }
コード例 #10
0
ファイル: AttributesIndex.cs プロジェクト: amseet/Orion
        private System.Collections.Generic.IDictionary <int[], uint> _collectionReverseIndex; // Holds all tag collections and their reverse index.

        /// <summary>
        /// Creates a new empty index.
        /// </summary>
        public AttributesIndex(AttributesIndexMode mode = AttributesIndexMode.ReverseCollectionIndex |
                               AttributesIndexMode.ReverseStringIndex)
        {
            _stringIndex            = new Index <string>();
            _collectionIndex        = new Index <int[]>();
            _isReadonly             = false;
            _mode                   = mode;
            _stringReverseIndex     = null;
            _collectionReverseIndex = null;

            if ((_mode & AttributesIndexMode.IncreaseOne) == AttributesIndexMode.IncreaseOne)
            {
                _index  = Context.ArrayFactory.CreateMemoryBackedArray <uint>(1024);
                _nextId = 0;
            }

            if ((_mode & AttributesIndexMode.ReverseStringIndex) == AttributesIndexMode.ReverseStringIndex ||
                (_mode & AttributesIndexMode.ReverseStringIndexKeysOnly) == AttributesIndexMode.ReverseStringIndexKeysOnly)
            {
                _stringReverseIndex = new System.Collections.Generic.Dictionary <string, int>();
            }
            if ((_mode & AttributesIndexMode.ReverseCollectionIndex) == AttributesIndexMode.ReverseCollectionIndex)
            {
                _collectionReverseIndex = new System.Collections.Generic.Dictionary <int[], uint>(
                    new DelegateEqualityComparer <int[]>(
                        (obj) =>
                {         // assumed the array is sorted.
                    var hash = obj.Length.GetHashCode();
                    for (int idx = 0; idx < obj.Length; idx++)
                    {
                        hash = hash ^ obj[idx].GetHashCode();
                    }
                    return(hash);
                },
                        (x, y) =>
                {
                    if (x.Length == y.Length)
                    {
                        for (int idx = 0; idx < x.Length; idx++)
                        {
                            if (x[idx] != y[idx])
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                    return(false);
                }));
            }
        }
コード例 #11
0
 public AttributesIndex(AttributesIndexMode mode = AttributesIndexMode.ReverseAll)
 {
     this._stringIndex            = new Index <string>();
     this._collectionIndex        = new Index <int[]>();
     this._isReadonly             = false;
     this._mode                   = mode;
     this._stringReverseIndex     = (IDictionary <string, int>)null;
     this._collectionReverseIndex = (IDictionary <int[], uint>)null;
     if ((this._mode & AttributesIndexMode.IncreaseOne) == AttributesIndexMode.IncreaseOne)
     {
         this._index  = (ArrayBase <uint>) new MemoryArray <uint>(1024L);
         this._nextId = 0U;
     }
     if ((this._mode & AttributesIndexMode.ReverseStringIndex) == AttributesIndexMode.ReverseStringIndex || (this._mode & AttributesIndexMode.ReverseStringIndexKeysOnly) == AttributesIndexMode.ReverseStringIndexKeysOnly)
     {
         this._stringReverseIndex = (IDictionary <string, int>) new Reminiscence.Collections.Dictionary <string, int>();
     }
     if ((this._mode & AttributesIndexMode.ReverseCollectionIndex) != AttributesIndexMode.ReverseCollectionIndex)
     {
         return;
     }
     DelegateEqualityComparer <int[]> .GetHashCodeDelegate hashCodeDelegate1 = (DelegateEqualityComparer <int[]> .GetHashCodeDelegate)(obj =>
     {
         int hashCode = obj.Length.GetHashCode();
         for (int index = 0; index < obj.Length; ++index)
         {
             hashCode ^= obj[index].GetHashCode();
         }
         return(hashCode);
     });
     this._collectionReverseIndex = (IDictionary <int[], uint>) new Reminiscence.Collections.Dictionary <int[], uint>((IEqualityComparer <int[]>) new DelegateEqualityComparer <int[]>(hashCodeDelegate1, (DelegateEqualityComparer <int[]> .EqualsDelegate)((x, y) =>
     {
         if (x.Length != y.Length)
         {
             return(false);
         }
         for (int index = 0; index < x.Length; ++index)
         {
             if (x[index] != y[index])
             {
                 return(false);
             }
         }
         return(true);
     })));
 }