예제 #1
0
파일: DLL.cs 프로젝트: cephdon/ROS.NET
 public DLL()
 {
     _first         = new DLLNode <T>();
     _last          = new DLLNode <T>();
     _first.next    = _last;
     _last.previous = _first;
 }
예제 #2
0
파일: DLL.cs 프로젝트: cephdon/ROS.NET
 public void pushBack(T t)
 {
     lock (this)
     {
         DLLNode <T> newnode = new DLLNode <T>(t);
         newnode.next        = _last;
         newnode.previous    = _last.previous;
         _last.previous.next = newnode;
         _last.previous      = newnode;
         count++;
     }
 }
예제 #3
0
파일: DLL.cs 프로젝트: cephdon/ROS.NET
 public void pushFront(T t)
 {
     lock (this)
     {
         DLLNode <T> newnode = new DLLNode <T>(t);
         _first.next.previous = newnode;
         newnode.next         = _first.next;
         newnode.previous     = _first;
         _first.next          = newnode;
         count++;
     }
 }
예제 #4
0
파일: DLL.cs 프로젝트: cephdon/ROS.NET
        private T _popBack()
        {
            if (_last.previous == _first)
            {
                return(default(T));
            }
            DLLNode <T> deadnode = _last.previous;

            _last.previous         = deadnode.previous;
            deadnode.previous.next = _last;
            count--;
            return(deadnode.element);
        }
예제 #5
0
파일: DLL.cs 프로젝트: cephdon/ROS.NET
        private T _popFront()
        {
            if (_first.next == _last)
            {
                return(default(T));
            }
            DLLNode <T> deadnode = _first.next;

            _first.next            = deadnode.next;
            deadnode.next.previous = _first;
            count--;
            return(deadnode.element);
        }
예제 #6
0
파일: DLL.cs 프로젝트: cephdon/ROS.NET
 public T spliceOut(DLLClosestNode <T> comp)
 {
     lock (this)
     {
         for (DLLNode <T> curr = _first.next; curr != _last; curr = curr.next)
         {
             DLLNode <T> deadnode = null;
             if ((deadnode = comp(curr, curr.next)) != null)
             {
                 deadnode.previous.next = deadnode.next;
                 deadnode.next.previous = deadnode.previous;
                 count--;
                 return(deadnode.element);
             }
         }
     }
     return(default(T));
 }
예제 #7
0
파일: DLL.cs 프로젝트: cephdon/ROS.NET
 public T spliceOut(T spliceout)
 {
     lock (this)
     {
         for (DLLNode <T> curr = _first.next; curr != _last; curr = curr.next)
         {
             if (curr.element.Equals(spliceout))
             {
                 DLLNode <T> deadnode = curr;
                 deadnode.previous.next = deadnode.next;
                 deadnode.next.previous = deadnode.previous;
                 count--;
                 return(deadnode.element);
             }
         }
     }
     return(default(T));
 }
예제 #8
0
파일: DLL.cs 프로젝트: cephdon/ROS.NET
 public void insert(T t, DLLInsertionPoint <T> comp)
 {
     lock (this)
     {
         for (DLLNode <T> curr = _first.next; curr != _last; curr = curr.next)
         {
             if (comp(t, curr.element))
             {
                 DLLNode <T> newnode = new DLLNode <T>(t);
                 curr.next.previous = newnode;
                 newnode.next       = curr.next;
                 newnode.previous   = curr;
                 curr.next          = newnode;
                 count++;
                 return;
             }
         }
         pushBack(t);
         count++;
     }
 }
예제 #9
0
파일: DLL.cs 프로젝트: cephdon/ROS.NET
 public T this[UInt64 key]
 {
     get
     {
         if (key >= count || key < 0)
         {
             throw new Exception("WTF?!");
         }
         bool   forwards = (key - (count / 2) > 0);
         UInt64 c        = forwards ? 0 : count - 1;
         lock (this)
             for (DLLNode <T> curr = forwards ? _first.next : _last.previous; forwards ? curr != _last : curr != _first; curr = walk(forwards, curr))
             {
                 if (c == key)
                 {
                     return(curr.element);
                 }
                 if (forwards)
                 {
                     c++;
                 }
                 else
                 {
                     c--;
                 }
             }
         return(default(T));
     }
     set
     {
         if (key >= count || key < 0)
         {
             throw new Exception("WTF?!");
         }
         bool        forwards = (key - (count / 2) < 0);
         UInt64      c        = forwards ? 0 : count - 1;
         DLLNode <T> newnode;
         lock (this)
         {
             for (DLLNode <T> curr = forwards ? _first.next : _last.previous; forwards ? curr != _last : curr != _first; curr = walk(forwards, curr))
             {
                 if (c == key)
                 {
                     newnode            = new DLLNode <T>(value);
                     curr.next.previous = newnode;
                     curr.next          = newnode;
                     newnode.next       = curr.next;
                     newnode.previous   = curr;
                     count++;
                     return;
                 }
                 if (forwards)
                 {
                     c++;
                 }
                 else
                 {
                     c--;
                 }
             }
             newnode             = new DLLNode <T>(value);
             _last.previous.next = newnode;
             _last.previous      = newnode;
             newnode.previous    = _last.previous;
             newnode.next        = _last;
             count++;
         }
     }
 }
예제 #10
0
파일: DLL.cs 프로젝트: cephdon/ROS.NET
 private DLLNode <T> walk(bool forwards, DLLNode <T> node)
 {
     return(forwards ? node.next : node.previous);
 }