Example #1
0
        internal bool Remove(long seqNum)
        {
            SkipListNode current = _head;
            bool         found   = false;

            lock (_lock)
            {
                for (int i = _levels - 1; i >= 0; i--)
                {
                    for (; current.Neighbors[i] != null; current = current.Neighbors[i])
                    {
                        if (current.Neighbors[i].seqNum == seqNum)
                        {
                            PublishContext ctx = current.Neighbors[i].ctx;

                            current.Neighbors[i] = current.Neighbors[i].Neighbors[i];
                            found = true;
                            count--;
                            break;
                        }

                        if (current.Neighbors[i].seqNum > seqNum)
                        {
                            if (!found)
                            {
                                found = false;
                                break;
                            }
                        }
                    }
                }
            }
            return(found);
        }
Example #2
0
 internal void Clear()
 {
     lock (_lock)
     {
         _head   = new SkipListNode(0, null, 33);
         _levels = 1;
     }
 }
Example #3
0
 internal void Clear()
 {
     lock (_lock)
     {
         _head   = new SkipListNode(0, default(T), 33);
         _levels = 1;
     }
 }
Example #4
0
        internal ArrayList Values()
        {
            ArrayList    list    = new ArrayList();
            SkipListNode current = _head.Neighbors[0];

            while (current != null)
            {
                list.Add(current.ctx);
                current = current.Neighbors[0];
            }
            return(list);
        }
Example #5
0
        internal bool Remove(long seqNum, out T returnValue)
        {
            SkipListNode current = _head;
            bool         found   = false;

            returnValue = default(T);

            lock (_lock)
            {
                for (int i = _levels - 1; i >= 0; i--)
                {
                    for (; current.Neighbors[i] != null; current = current.Neighbors[i])
                    {
                        if (current.Neighbors[i].seqNum == seqNum)
                        {
                            T data = current.Neighbors[i].data;

                            current.Neighbors[i] = current.Neighbors[i].Neighbors[i];
                            returnValue          = data;
                            found = true;
                            count--;
                            break;
                        }

                        if (current.Neighbors[i].seqNum > seqNum)
                        {
                            if (!found)
                            {
                                found       = false;
                                returnValue = default(T);
                                break;
                            }
                        }
                    }
                }
            }

            if (!found)
            {
                returnValue = default(T);
            }

            return(found);
        }
Example #6
0
        internal void Put(long seqNum, PublishContext ctx)
        {
            lock (_lock)
            {
                int level  = 0;
                int random = _rand.Next();

                for (int R = random; (R & 1) == 1; R >>= 1)
                {
                    level++;
                    if (level == _levels)
                    {
                        _levels++;
                        break;
                    }
                }

                // Insert this node into the skip list
                SkipListNode newNode = new SkipListNode(seqNum, ctx, level + 1);
                count++;
                SkipListNode current = _head;

                for (int i = _levels - 1; i >= 0; i--)
                {
                    for (; current.Neighbors[i] != null; current = current.Neighbors[i])
                    {
                        if (current.Neighbors[i].seqNum > seqNum)
                        {
                            break;
                        }
                    }

                    if (i <= level)
                    {
                        newNode.Neighbors[i] = current.Neighbors[i];
                        current.Neighbors[i] = newNode;
                    }
                }
            }
        }
Example #7
0
        internal PublishContext Get(long seqNum)
        {
            SkipListNode current = _head;

            lock (_lock)
            {
                for (int i = _levels - 1; i >= 0; i--)
                {
                    for (; current.Neighbors[i] != null; current = current.Neighbors[i])
                    {
                        if (current.Neighbors[i].seqNum > seqNum)
                        {
                            break;
                        }

                        if (current.Neighbors[i].seqNum == seqNum)
                        {
                            return(current.Neighbors[i].ctx);
                        }
                    }
                }
                return(null);
            }
        }
Example #8
0
        internal T Get(long seqNum)
        {
            SkipListNode current = _head;

            lock (_lock)
            {
                for (int i = _levels - 1; i >= 0; i--)
                {
                    for (; current.Neighbors[i] != null; current = current.Neighbors[i])
                    {
                        if (current.Neighbors[i].seqNum > seqNum)
                        {
                            break;
                        }

                        if (current.Neighbors[i].seqNum == seqNum)
                        {
                            return(current.Neighbors[i].data);
                        }
                    }
                }
                return(default(T));
            }
        }