Пример #1
0
 public RBStore(string cacheName, string storeDataType, string name, bool haveDuplicateKeys)
 {
     this._storeDataType          = storeDataType;
     this.storeName               = name;
     _rbTree                      = new RedBlack <T>(cacheName, Common.MemoryUtil.GetAttributeTypeSize(storeDataType));
     _rbTree.CanHaveDuplicateKeys = haveDuplicateKeys;
 }
Пример #2
0
        public ArrayList GetData(object key, ComparisonType comparisonType)
        {
            RedBlack <T> .COMPARE compare = RedBlack <T> .COMPARE.EQ;
            ArrayList             result  = new ArrayList();

            if (_rbTree != null)
            {
                switch (comparisonType)
                {
                case ComparisonType.EQUALS:
                    compare = RedBlack <T> .COMPARE.EQ;
                    break;

                case ComparisonType.NOT_EQUALS:
                    compare = RedBlack <T> .COMPARE.NE;
                    break;

                case ComparisonType.LESS_THAN:
                    compare = RedBlack <T> .COMPARE.LT;
                    break;

                case ComparisonType.GREATER_THAN:
                    compare = RedBlack <T> .COMPARE.GT;
                    break;

                case ComparisonType.LESS_THAN_EQUALS:
                    compare = RedBlack <T> .COMPARE.LTEQ;
                    break;

                case ComparisonType.GREATER_THAN_EQUALS:
                    compare = RedBlack <T> .COMPARE.GTEQ;
                    break;

                case ComparisonType.LIKE:
                    compare = RedBlack <T> .COMPARE.REGEX;
                    break;

                case ComparisonType.NOT_LIKE:
                    compare = RedBlack <T> .COMPARE.IREGEX;
                    break;
                }
                try
                {
                    if (key is T)
                    {
                        result = _rbTree.GetData((T)key, compare) as ArrayList;
                    }
                    else
                    {
                        throw new Exception("Object must be of type " + _storeDataType);
                    }
                }
                catch
                {
                    throw;
                }
            }

            return(result);
        }
Пример #3
0
        private static void TraverseRedBlack(RedBlack redBlack)
        {
            // Depth-first traversal
            PrintSize(redBlack);
            var stack = new Stack <RedBlackNode>();

            stack.Push((RedBlackNode)redBlack.Root);
            while (stack.Count != 0)
            {
                var         node      = stack.Pop();
                IComparable parentKey = null;
                if (node.Left != RedBlack.SentinelNode)
                {
                    stack.Push(node.Left);
                }

                if (node.Right != RedBlack.SentinelNode)
                {
                    stack.Push(node.Right);
                }

                if (node.Parent != null)
                {
                    parentKey = node.Parent.Key;
                }

                PrintRedBlackNode(node, parentKey);
            }
        }
Пример #4
0
        public void Test()
        {
            /*
            var bst=new Avl<int>();
            bst.Insert(1);
            bst.Insert(2);
            bst.Insert(3);
            bst.Insert(4);
            bst.Remove(1);
            Console.WriteLine(bst.Root.Data);
            bst.TravIn(new Action<int>(i => Console.WriteLine(i)));
             */
           /* var bst = new Splay<int>();
            bst.Insert(4);         
            bst.Insert(8);
            bst.Insert(6);
            Console.WriteLine(bst.Root.Data);
            Console.WriteLine(bst.Root.LChild.Data);
            Console.WriteLine(bst.Root.RChild.Data);
            */
            //Console.WriteLine(bst.Root.Data);
            //Console.WriteLine(bst.Root.LChild.Data);
            //Console.WriteLine(bst.Root.LChild.RChild.Data);
            //Console.WriteLine(bst.Root.LChild.RChild.LChild.Data);
            //Console.WriteLine(bst.Root.LChild.LChild.Data);
            //Console.WriteLine(bst.Root.RChild.Data);
          //  Console.WriteLine(bst.Root.RChild.Data);
          //  Console.WriteLine(bst.Root.RChild.RChild.Data);
            //Console.WriteLine(bst.Root.RChild.RChild.RChild.Data);
            //Console.WriteLine(bst.Root.LChild.Data);
            //Console.WriteLine(bst.Root.LChild.LChild.Data);
           // Console.WriteLine();
            //bst.Insert(3);
           // Console.WriteLine(x.Data);
          //  bst.Insert(1);
           // Console.WriteLine(bst.Root.Data);
            //Console.WriteLine(bst.Root.RChild.Data);
            //Console.WriteLine(bst.Root.RChild.RChild.Data);
        //  bst.TravIn(new Action<int>(i => Console.WriteLine(i)));
            //BTree<int> bt=new BTree<int>();
            //bt.Insert(2);
            //bt.Insert(3);
            //bt.Insert(5);
            //bt.Insert(6);
            //bt.Remove(5);
         //  bt.Root.Key.ForEach(new Action<int>(i => Console.WriteLine(i)));
           // Console.WriteLine(bt.Root.Key[0]);
            var bt = new RedBlack<int>();
            bt.Insert(1);
            bt.Insert(2);
            bt.Insert(3);
            bt.Insert(0);
            bt.Remove(3);
            Console.WriteLine(bt.Root.Data);
            Console.WriteLine(bt.Root.Color);

        }
Пример #5
0
        private static bool isPolygonSimple(double[,] polygon, int n)
        {
            Comparer comparer = new Comparer();
            SortedDictionary <Edge, object> vertices = new SortedDictionary <Edge, object>(comparer);

            try
            {
                for (int i = 1; i <= n; i++)
                {
                    vertices.Add(new Edge(polygon[i % n, 0], polygon[i % n, 1], polygon[(i + 1) % n, 0], polygon[(i + 1) % n, 1]), null);
                    vertices.Add(new Edge(polygon[i % n, 0], polygon[i % n, 1], polygon[(i - 1) % n, 0], polygon[(i - 1) % n, 1]), null);
                }

                RedBlack tree = new RedBlack();
                foreach (var vertex in vertices)
                {
                    Edge edge = vertex.Key;
                    if (comparer.Compare(edge.A, edge.B) < 0)
                    {
                        tree.Add(edge, new object());
                        IComparable below, above;
                        tree.GetKeysDirectlyAboveAndBelow(edge, out below, out above);

                        if (below != null && ((Edge)below).Crosses(edge))
                        {
                            return(false);
                        }
                        if (above != null && ((Edge)above).Crosses(edge))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        edge = new Edge(edge.B[0], edge.B[1], edge.A[0], edge.A[1]);
                        IComparable below, above;

                        tree.GetKeysDirectlyAboveAndBelow(edge, out below, out above);
                        if (below != null && above != null && ((Edge)below).Crosses((Edge)above))
                        {
                            return(false);
                        }
                        tree.Remove(edge);
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #6
0
        public void GetData(object key, ComparisonType comparisonType, IQueryResult result, CollectionOperation mergeType, CancellationToken token)

        {
            RedBlack <T> .COMPARE compare = RedBlack <T> .COMPARE.EQ;

            if (_rbTree != null)
            {
                switch (comparisonType)
                {
                case ComparisonType.EQUALS:
                    compare = RedBlack <T> .COMPARE.EQ;
                    break;

                case ComparisonType.NOT_EQUALS:
                    compare = RedBlack <T> .COMPARE.NE;
                    break;

                case ComparisonType.LESS_THAN:
                    compare = RedBlack <T> .COMPARE.LT;
                    break;

                case ComparisonType.GREATER_THAN:
                    compare = RedBlack <T> .COMPARE.GT;
                    break;

                case ComparisonType.LESS_THAN_EQUALS:
                    compare = RedBlack <T> .COMPARE.LTEQ;
                    break;

                case ComparisonType.GREATER_THAN_EQUALS:
                    compare = RedBlack <T> .COMPARE.GTEQ;
                    break;

                case ComparisonType.LIKE:
                    compare = RedBlack <T> .COMPARE.REGEX;
                    break;

                case ComparisonType.NOT_LIKE:
                    compare = RedBlack <T> .COMPARE.IREGEX;
                    break;
                }
                if (key is T)
                {
                    _rbTree.GetData((T)key, compare, result, mergeType, token);
                }
                else
                {
                    throw new InvalidCastException("Object must be of type " + typeof(T).Name);
                }
            }
        }
Пример #7
0
        private static void Main(string[] args)
        {
            Avl <int, string>        avlTree = new Avl <int, string>();
            RedBlack <int, string>   rbTree  = new RedBlack <int, string>();
            Dictionary <int, string> dicTree = new Dictionary <int, string>();

            int entriesNumber = 0;

            Console.Write("Enter entries number (1 if 320, 2 if 640 3 if 1280) : ");

            switch (int.Parse(Console.ReadLine()))
            {
            case 1:
                entriesNumber = 320;
                break;

            case 2:
                entriesNumber = 640;
                break;

            case 3:
                entriesNumber = 1280;
                break;
            }

            Tester(avlTree, entriesNumber, out TimeTester avlTimeTester);
            Tester(rbTree, entriesNumber, out TimeTester rbTimeTester);
            Tester(dicTree, entriesNumber, out TimeTester dicTimeTester);

            avlTimeTester.Print();
            Console.WriteLine();
            rbTimeTester.Print();
            Console.WriteLine();
            dicTimeTester.Print();
            Console.WriteLine();
        }
Пример #8
0
 public OperationLogger(int bucketId, LogMode loggingMode)
 {
     _bucketId    = bucketId;
     _opIndex     = new RedBlack <HPTime>();
     _loggingMode = loggingMode;
 }
Пример #9
0
 public KetamaNodeLocator()
 {
     ketamaNodes = new RedBlack <ulong, StoreNode>("node");
 }
Пример #10
0
 public RBStore(string cacheName, string storeDataType, string name)
 {
     this._storeDataType = storeDataType;
     storeName           = name;
     _rbTree             = new RedBlack <T>(cacheName, Common.MemoryUtil.GetAttributeTypeSize(storeDataType));
 }
Пример #11
0
 public void RedBlackInit()
 {
     this.redBlack = new RedBlack();
 }
Пример #12
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="cacheName">Nome do cache.</param>
 public RBStore(string cacheName)
 {
     _rbTree = new RedBlack(cacheName);
 }
Пример #13
0
 public SortedAndIndexedBlockingQueue(int capacity)
 {
     this.capacity = capacity;
     this.redBlack = new RedBlack();
     this.nodeMap  = new Dictionary <object, SequentialNode <TItem> >();
 }