Exemple #1
0
 public k_Iterator Erase(k_Iterator ak_Where)
 {
     //System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");
     int li_Index = ((k_IListIterator)ak_Where).Index;
     if (li_Index < this.Count)
         base.RemoveAt(li_Index);
     return new k_IListIterator(this, li_Index);
 }
Exemple #2
0
 public static k_Iterator Find(k_Iterator ak_First, k_Iterator ak_Last, object ak_Value)
 {
     k_Iterator lk_Iter = ak_First.Clone();
     for (; lk_Iter != ak_Last; lk_Iter.Next())
     {
         if (object.Equals(lk_Iter.Current, ak_Value))
             break;
     }
     return lk_Iter;
 }
Exemple #3
0
 public k_SkipList(IComparer ak_Comparer, double ad_Prob, int ai_MaxLevel)
 {
     if (ad_Prob >= 1.0 || ad_Prob <= 0)
         throw new ArgumentException("Invalid probability. Must be (0-1).", "ad_Prob");
     md_Prob = ad_Prob;
     mi_MaxLevel = ai_MaxLevel;
     mk_Comparer = ak_Comparer;
     mk_Head = new k_Node(null, null, ai_MaxLevel);
     mk_End = new k_PinnedNodeIterator(this, null);
 }
Exemple #4
0
 public static k_Iterator Copy(k_Iterator ak_SrcFirst, k_Iterator ak_BehindSrcLast, k_Iterator ak_DstFirst)
 {
     k_Iterator lk_Src = ak_SrcFirst.Clone(), lk_Dst = ak_DstFirst.Clone();
     while (lk_Src != ak_BehindSrcLast)
     {
         lk_Dst.Current = lk_Src.Current;
         lk_Src.Next(); lk_Dst.Next();
     }
     return lk_Dst;
 }
Exemple #5
0
 public static k_Iterator CopyBackward(k_Iterator ak_SrcFirst, k_Iterator ak_BehindSrcLast, k_Iterator ak_BehindDstLast)
 {
     k_Iterator lk_Src = ak_BehindSrcLast.Clone(), lk_Dst = ak_BehindDstLast.Clone();
     while (lk_Src != ak_SrcFirst)
     {
         lk_Src.Prev(); lk_Dst.Prev();
         lk_Dst.Current = lk_Src.Current;
     }
     return lk_Dst;
 }
Exemple #6
0
        public k_HashTable(int ai_Capacity, double ad_LoadFactor, IHashCodeProvider ak_HashProvider, IComparer ak_Comparer)
        {
            if (ad_LoadFactor <= .0 || ad_LoadFactor > 1.0)
                throw new ArgumentException("Load factor must be greater than .0 and smaller or equal to 1.0", "ad_LoadFactor");
            md_LoadFactor = ad_LoadFactor;

            double ld_Size = ai_Capacity/ad_LoadFactor;
            if (ld_Size > int.MaxValue)
                throw new ArgumentException("k_HashTable overflow");

            int li_TableSize = FindPrimeGreater((int)ld_Size);
            mk_Buckets = new r_Bucket[li_TableSize];
            mi_GrowSize = (md_LoadFactor < 1.0) ? (int)(md_LoadFactor * li_TableSize) : li_TableSize-1;

            mk_HashProvider = ak_HashProvider;
            mk_Comparer = ak_Comparer;

            mk_End = new k_PinnedBucketIterator(this, -1);
        }
Exemple #7
0
 public void Insert(k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
 {
     for (k_Iterator lk_Iter = ak_SrcBegin.Clone(); lk_Iter != ak_SrcEnd; lk_Iter.Next())
         Add((DictionaryEntry)lk_Iter.Current);
 }
Exemple #8
0
        private void PasteNodeRange(k_NodeIterator ak_Where, k_Node ak_First, k_Node ak_Last)
        {
            if (ak_Where != this.End)
            {
                k_Node lk_Next = ak_Where.Node;
                k_Node lk_Prev = lk_Next.mk_Prev;

                ak_Last.mk_Next = lk_Next;
                ak_First.mk_Prev = lk_Prev;
                if (lk_Next != null)
                    lk_Next.mk_Prev = ak_Last;
                if (lk_Prev != null)
                    lk_Prev.mk_Next = ak_First;
            }
            else
            {
                if (mk_Tail != null)
                {
                    mk_Tail.mk_Next = ak_First;
                    ak_First.mk_Prev = mk_Tail;
                }
                mk_Tail = ak_Last;
            }

            if (ak_Where == this.Begin)
            {
                mk_Head = ak_First;
                mk_Begin = null;        // recalc on next get
            }
        }
Exemple #9
0
        public void Insert(k_Iterator ak_Where, k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
        {
            //System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");

            k_Node lk_Start = new k_Node(null), lk_End = lk_Start;

            int li_Count = 0;
            for (k_Iterator lk_Iter = ak_SrcBegin.Clone(); lk_Iter != ak_SrcEnd; lk_Iter.Next(), ++li_Count)
            {
                k_Node lk_New = new k_Node(lk_Iter.Current);
                lk_End.mk_Next = lk_New;
                lk_New.mk_Prev = lk_End;
                lk_End = lk_New;
            }

            if (li_Count > 0)
            {
                PasteNodeRange((k_NodeIterator)ak_Where, lk_Start.mk_Next, lk_End);
                mi_Count += li_Count;
            }
        }
Exemple #10
0
 public k_List()
 {
     mk_End = new k_PinnedNodeIterator(this, null);
     mk_Begin = mk_End;
 }
Exemple #11
0
 public void Insert(k_Iterator ak_Where, object ak_Value)
 {
     //System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");
     this.Insert(((k_IListIterator)ak_Where).Index, ak_Value);
 }
Exemple #12
0
 public void Assign(k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
 {
     Clear();
     Insert(this.End, ak_SrcBegin, ak_SrcEnd);
 }
Exemple #13
0
 public override int Distance(k_Iterator ak_Iter)
 {
     return mi_Index - ((k_IListIterator)ak_Iter).mi_Index;
 }
Exemple #14
0
        public k_Iterator Erase(k_Iterator ak_First, k_Iterator ak_Last)
        {
            //System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_First.Collection) && object.ReferenceEquals(this, ak_Last.Collection), "Iterators do not belong to this collection.");
            int li_FirstIndex = ((k_IListIterator)ak_First).Index;
            int li_Count = ak_Last - ak_First;

            base.RemoveRange(li_FirstIndex, li_Count);

            return new k_IListIterator(this, li_FirstIndex);
        }
Exemple #15
0
 public void Insert(k_Iterator ak_Where, object ak_Value, int ai_Count)
 {
     int li_Pos = ((k_IListIterator)ak_Where).Index;
     for (int i=0; i<ai_Count; ++i)
         base.Insert(li_Pos+i, ak_Value);
 }
Exemple #16
0
 public void Insert(k_Iterator ak_Where, k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
 {
     //System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");
     InsertRange(((k_IListIterator)ak_Where).Index, new k_CollectionOnIterators(ak_SrcBegin, ak_SrcEnd));
 }
Exemple #17
0
 public static void Fill(k_Iterator ak_DstFirst, k_Iterator ak_BehindDstLast, object ak_Value)
 {
     for (k_Iterator lk_Iter = ak_DstFirst.Clone(); lk_Iter != ak_BehindDstLast; lk_Iter.Next())
         lk_Iter.Current = ak_Value;
 }
Exemple #18
0
 public k_Iterator Erase(k_Iterator ak_Where)
 {
     //System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this list.");
     if (ak_Where == this.End)
         return this.End;
     return Erase(ak_Where, ak_Where + 1);
 }
Exemple #19
0
 public k_CollectionOnIterators(k_Iterator ak_Begin, k_Iterator ak_End)
 {
     mk_Begin = ak_Begin;
     mk_End = ak_End;
     mi_Count = mk_End - mk_Begin;
 }
Exemple #20
0
            public override int Distance(k_Iterator ak_Iter)
            {
                k_BucketIterator lk_Iter = ak_Iter as k_BucketIterator;
                if (lk_Iter == null || !object.ReferenceEquals(lk_Iter.Collection, this.Collection))
                    throw new ArgumentException("Cannot determine distance of iterators belonging to different collections.");

                k_Iterator lk_End = mk_Table.End;

                int li_IndexDiff;
                if (this != lk_End && ak_Iter != lk_End)
                    li_IndexDiff = mi_Index - lk_Iter.mi_Index;
                else
                    li_IndexDiff = (this == lk_End) ? 1 : -1;    // 1 is also fine when both are End

                if (li_IndexDiff < 0)
                {
                    int li_Diff = 0;
                    k_Iterator lk_Bck = this.Clone();
                    for (; lk_Bck != ak_Iter && lk_Bck != lk_End; lk_Bck.Next())
                        --li_Diff;

                    if (lk_Bck == ak_Iter)
                        return li_Diff;
                }
                else
                {
                    int li_Diff = 0;
                    k_Iterator lk_Fwd = ak_Iter.Clone();
                    for (; lk_Fwd != this && lk_Fwd != lk_End; lk_Fwd.Next())
                        ++li_Diff;

                    if (lk_Fwd == this)
                        return li_Diff;
                }

                throw new Exception("Inconsistent state. Concurrency?");
            }
Exemple #21
0
 public void Clear()
 {
     mk_Head = mk_Tail = null;
     mk_Begin = mk_End;
     mi_Count = 0;
 }
Exemple #22
0
 public abstract int Distance(k_Iterator ak_Iter);
Exemple #23
0
        public k_Iterator Erase(k_Iterator ak_First, k_Iterator ak_Last)
        {
            //System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_First.Collection) && object.ReferenceEquals(this, ak_Last.Collection), "Iterators do not belong to this collection.");
            int li_Distance = ak_Last - ak_First;
            if (li_Distance == 0)
                return ak_Last;

            k_Node lk_First = ((k_NodeIterator)ak_First).Node;
            k_Node lk_Prev = lk_First.mk_Prev;
            k_Node lk_Next = (ak_Last != this.End) ? ((k_NodeIterator)ak_Last).Node : null;

            if (lk_Prev != null)
                lk_Prev.mk_Next = lk_Next;
            else
            {
                //System.Diagnostics.Debug.Assert(object.ReferenceEquals(mk_Head, lk_First), "Inconsistent list state");
                mk_Head = lk_Next;
                mk_Begin = null;
            }

            if (lk_Next != null)
                lk_Next.mk_Prev = lk_Prev;
            else
            {
                //System.Diagnostics.Debug.Assert(object.ReferenceEquals(mk_Tail, ((k_NodeIterator)(ak_Last-1)).Node), "Inconsistent list state");
                mk_Tail = lk_Prev;
            }

            mi_Count -= li_Distance;

            #if (DEBUG)
            // create invalid nodes linking to itself
            k_Node lk_Node = lk_First;
            while (lk_Node != null && lk_Node != lk_Next)
            {
                k_Node lk_Tmp = lk_Node.mk_Next;
                lk_Node.mk_Next = lk_Node;
                lk_Node.mk_Prev = lk_Node;

                lk_Node = lk_Tmp;
            }
            #endif

            return ak_Last;
        }
Exemple #24
0
 public k_IteratorDictEnumerator(k_Iterator ak_Begin, k_Iterator ak_End)
     : base(ak_Begin, ak_End)
 {
 }
Exemple #25
0
        public void Insert(k_Iterator ak_Where, object ak_Value)
        {
            //System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");

            k_Node lk_New = new k_Node(ak_Value);
            PasteNodeRange((k_NodeIterator)ak_Where, lk_New, lk_New);
            ++mi_Count;
        }
Exemple #26
0
 public k_IteratorEnumerator(k_Iterator ak_Begin, k_Iterator ak_End)
 {
     mk_Begin = ak_Begin;
     mk_End = ak_End;
     mb_Fresh = true;
 }
Exemple #27
0
        public void Insert(k_Iterator ak_Where, object ak_Value, int ai_Count)
        {
            //System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");

            k_Node lk_Start = new k_Node(null), lk_End = lk_Start;

            for (int i=0; i<ai_Count; ++i)
            {
                k_Node lk_New = new k_Node(ak_Value);
                lk_End.mk_Next = lk_New;
                lk_New.mk_Prev = lk_End;
                lk_End = lk_New;
            }

            if (ai_Count > 0)
            {
                PasteNodeRange((k_NodeIterator)ak_Where, lk_Start.mk_Next, lk_End);
                mi_Count += ai_Count;
            }
        }
Exemple #28
0
        public bool MoveNext()
        {
            if (mb_Fresh)
            {
                mk_Current = mk_Begin.Clone();
                mb_Fresh = false;
            }
            else if (mk_Current != mk_End)
                mk_Current.Next();

            return (mk_Current != mk_End);
        }
Exemple #29
0
            public override int Distance(k_Iterator ak_Iter)
            {
                k_NodeIterator lk_Iter = (k_NodeIterator)ak_Iter;

                if (!this.IsValid || !lk_Iter.IsValid)
                    throw new ArgumentException("Iterator is invalid.");

                int li_Diff = 0;
                k_Iterator lk_End = mk_List.End;
                k_Iterator lk_Fwd = lk_Iter.Clone();
                for (; lk_Fwd != this && lk_Fwd != lk_End; lk_Fwd.Next())
                    ++li_Diff;

                if (lk_Fwd == this)
                    return li_Diff;

                li_Diff = 0;
                k_Iterator lk_Bck = this.Clone();
                for (; lk_Bck != lk_Iter && lk_Bck != lk_End; lk_Bck.Next())
                    --li_Diff;

                if (lk_Bck == lk_Iter)
                    return li_Diff;

                throw new Exception("Inconsistent state. Concurrency?");
            }
Exemple #30
0
 public void Reset()
 {
     mb_Fresh = true;
     mk_Current = null;
 }