Exemplo n.º 1
0
        private static OrderedIndex populate(params int[] valueKeys)
        {
            //register the type to get a valid TypeDescription
            //the type description is used to create CachedObjects from objects of the registered type
            var typeDescription = ClientSideTypeDescription.RegisterType(typeof(CacheableTypeOk));

            KeyInfo valueKey = null;

            foreach (var keyInfo in typeDescription.IndexFields)
            {
                if (keyInfo.Name == "IndexKeyValue")
                {
                    valueKey = keyInfo.AsKeyInfo;
                }
            }

            Assert.IsNotNull(valueKey);

            var index = new OrderedIndex(valueKey);

            for (var i = 0; i < valueKeys.Length; i++)
            {
                index.Put(CachedObject.Pack(new CacheableTypeOk(i, 106, "A", DateTime.Now, valueKeys[i])));
            }

            return(index);
        }
Exemplo n.º 2
0
        private static OrderedIndex Populate(params int[] valueKeys)
        {
            var schema = TypedSchemaFactory.FromType <CacheableTypeOk>();

            //register the type to get a valid CollectionSchema
            //the type description is used to create CachedObjects from objects of the registered type
            var typeDescription = TypedSchemaFactory.FromType(typeof(CacheableTypeOk));

            KeyInfo valueKey = null;

            foreach (var keyInfo in typeDescription.IndexFields)
            {
                if (keyInfo.Name == "IndexKeyValue")
                {
                    valueKey = keyInfo;
                }
            }

            Assert.IsNotNull(valueKey);

            var index = new OrderedIndex(valueKey);

            for (var i = 0; i < valueKeys.Length; i++)
            {
                index.Put(PackedObject.Pack(new CacheableTypeOk(i, 106, "A", DateTime.Now, valueKeys[i]), schema));
            }

            return(index);
        }
Exemplo n.º 3
0
        public void Lesser()
        {
            //register the type to get a valid TypeDescription
            //the type description is used to create CachedObjects from objects of the registered type
            var typeDescription = ClientSideTypeDescription.RegisterType(typeof(CacheableTypeOk));

            KeyInfo valueKey = null;

            foreach (var keyInfo in typeDescription.IndexFields)
            {
                if (keyInfo.Name == "IndexKeyValue")
                {
                    valueKey = keyInfo.AsKeyInfo;
                }
            }

            Assert.IsNotNull(valueKey);


            //fill in order
            {
                var indexByValue = new OrderedIndex(valueKey);

                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 1)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 4)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 6)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 13)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 14)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 80)));

                checkLE(indexByValue);
                checkLS(indexByValue);
            }

            //fill out of order
            {
                var indexByValue = new OrderedIndex(valueKey);

                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 80)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 1)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 13)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 4)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 14)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 6)));


                checkLE(indexByValue);
                checkLS(indexByValue);
            }

            //fill out of order transactional
            {
                var indexByValue = new OrderedIndex(valueKey);

                indexByValue.BeginFill();

                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 80)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 1)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 13)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 4)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 14)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 6)));
                indexByValue.EndFill();

                checkLE(indexByValue);
                checkLS(indexByValue);
            }


            //all equals
            {
                var indexByValue = new OrderedIndex(valueKey);

                var keyType = new KeyInfo(KeyDataType.IntKey, KeyType.ScalarIndex, "test", true);

                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 45)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 45)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 45)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 45)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 45)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 45)));

                //value not fount (too small)
                var result1 = indexByValue.GetMany(MakeIntValue(12, keyType), QueryOperator.Le);
                Assert.AreEqual(result1.Count, 0);

                result1 = indexByValue.GetMany(MakeIntValue(12, keyType), QueryOperator.Lt);
                Assert.AreEqual(result1.Count, 0);

                //value not found (too big)
                result1 = indexByValue.GetMany(MakeIntValue(50, keyType), QueryOperator.Le);
                Assert.AreEqual(result1.Count, 6);

                result1 = indexByValue.GetMany(MakeIntValue(50, keyType), QueryOperator.Lt);
                Assert.AreEqual(result1.Count, 6);

                //value found (all match the index key )
                result1 = indexByValue.GetMany(MakeIntValue(45, keyType), QueryOperator.Le);
                Assert.AreEqual(result1.Count, 6);

                //not found (Lt)
                result1 = indexByValue.GetMany(MakeIntValue(45, keyType), QueryOperator.Lt);
                Assert.AreEqual(result1.Count, 0);
            }
        }
Exemplo n.º 4
0
        public void Lesser()
        {
            var schema = TypedSchemaFactory.FromType <CacheableTypeOk>();

            //register the type to get a valid CollectionSchema
            //the type description is used to create CachedObjects from objects of the registered type
            var typeDescription = TypedSchemaFactory.FromType(typeof(CacheableTypeOk));

            KeyInfo valueKey = null;

            foreach (var keyInfo in typeDescription.IndexFields)
            {
                if (keyInfo.Name == "IndexKeyValue")
                {
                    valueKey = keyInfo;
                }
            }

            Assert.IsNotNull(valueKey);


            //fill in order
            {
                var indexByValue = new OrderedIndex(valueKey);

                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 1), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 4), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 6), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 13), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 14), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 80), schema));

                CheckLe(indexByValue);
                CheckLs(indexByValue);
            }

            //fill out of order
            {
                var indexByValue = new OrderedIndex(valueKey);

                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 80), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 1), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 13), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 4), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 14), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 6), schema));


                CheckLe(indexByValue);
                CheckLs(indexByValue);
            }

            //fill out of order transactional
            {
                var indexByValue = new OrderedIndex(valueKey);

                indexByValue.BeginFill();

                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 80), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 1), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 13), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 4), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 14), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 6), schema));
                indexByValue.EndFill();

                CheckLe(indexByValue);
                CheckLs(indexByValue);
            }


            //all equals
            {
                var indexByValue = new OrderedIndex(valueKey);

                var keyType = new KeyInfo("test", 0, IndexType.Ordered);

                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 45), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 45), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 45), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 45), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 45), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 45), schema));

                //value not fount (too small)
                var result1 = indexByValue.GetMany(MakeIntValue(12, keyType), QueryOperator.Le);
                Assert.AreEqual(result1.Count, 0);

                result1 = indexByValue.GetMany(MakeIntValue(12, keyType), QueryOperator.Lt);
                Assert.AreEqual(result1.Count, 0);

                //value not found (too big)
                result1 = indexByValue.GetMany(MakeIntValue(50, keyType), QueryOperator.Le);
                Assert.AreEqual(result1.Count, 6);

                result1 = indexByValue.GetMany(MakeIntValue(50, keyType), QueryOperator.Lt);
                Assert.AreEqual(result1.Count, 6);

                //value found (all match the index key )
                result1 = indexByValue.GetMany(MakeIntValue(45, keyType), QueryOperator.Le);
                Assert.AreEqual(result1.Count, 6);

                //not found (Lt)
                result1 = indexByValue.GetMany(MakeIntValue(45, keyType), QueryOperator.Lt);
                Assert.AreEqual(result1.Count, 0);
            }
        }
        private static int AddToDictionary(
            Dictionary <string, OrderedIndex> identityDictionary,
            List <T> orderedList,
            string identity,
            int index,
            bool updateIfFound)
        {
            DebugCheck.NotNull(identityDictionary);
            DebugCheck.NotNull(orderedList);
            DebugCheck.NotEmpty(identity);

            int[]        inexact = null;
            OrderedIndex orderIndex;
            var          exactIndex = index;

            // find the item(s) by OrdinalIgnoreCase
            if (identityDictionary.TryGetValue(identity, out orderIndex))
            {
                // identity was already tracking an item, verify its not a duplicate by exact name
                if (EqualIdentity(orderedList, orderIndex.ExactIndex, identity))
                {
                    // If the item is already here and we are updating, there is no more work to be done.
                    if (updateIfFound)
                    {
                        return(orderIndex.ExactIndex);
                    }

                    throw new ArgumentException(Strings.ItemDuplicateIdentity(identity), "item", null);
                }

                if (null != orderIndex.InexactIndexes)
                {
                    // search against the ExactIndex and all InexactIndexes
                    // identity was already tracking multiple items, verify its not a duplicate by exact name
                    for (var i = 0; i < orderIndex.InexactIndexes.Length; ++i)
                    {
                        if (EqualIdentity(orderedList, orderIndex.InexactIndexes[i], identity))
                        {
                            // If the item is already here and we are updating, there is no more work to be done.
                            if (updateIfFound)
                            {
                                return(orderIndex.InexactIndexes[i]);
                            }

                            throw new ArgumentException(Strings.ItemDuplicateIdentity(identity), "item", null);
                        }
                    }
                    // add another item for existing identity that already was tracking multiple items
                    inexact = new int[orderIndex.InexactIndexes.Length + 1];
                    orderIndex.InexactIndexes.CopyTo(inexact, 0);
                    inexact[inexact.Length - 1] = index;
                }
                else
                {
                    // turn the previously unique identity by ignore case into a multiple item for identity by ignore case
                    inexact = new int[1] {
                        index
                    };
                }
                // the index of the item whose identity was used to create the initial dictionary entry
                exactIndex = orderIndex.ExactIndex;
            }
            // else this is a new identity

            identityDictionary[identity] = new OrderedIndex(exactIndex, inexact);

            return(index);
        }