Exemple #1
0
        void UpdateAntichain()
        {
            Antichain.Clear();
            for (int i = 0; i < elements.Count; i++)
            {
                if (precedents.Array[i] == 0)
                {
                    Antichain.Add(elements.Array[i]);
                }
            }

            if (Antichain.Count == 0 && elements.Count > 0)
            {
                throw new Exception("Empty Antichain from non-empty set");
            }
        }
Exemple #2
0
        internal Handle <T> Allocate(int LogLength)
        {
            if (FreeList.Count > 0)
            {
                var region = FreeList.RemoveAtAndReturn(FreeList.Count - 1);
                return(this.Dereference(new Descriptor(LogLength, region)));
            }
            else
            {
                // make sure there are enough elements available
                while (Spine.Count * SegmentLength < (Allocated + 1) * Length)
                {
                    Spine.Add(new T[SegmentLength]);
                }

                return(this.Dereference(new Descriptor(LogLength, Allocated++)));
            }
        }
Exemple #3
0
        public bool Add(T element)
        {
            var newPrecedents = 0;

            for (int i = 0; i < elements.Count; i++)
            {
                if (element.LessThan(elements.Array[i]))
                {
                    precedents.Array[i]++;
                }

                if (elements.Array[i].LessThan(element))
                {
                    newPrecedents++;
                }

                if (element.LessThan(elements.Array[i]) && elements.Array[i].LessThan(element) && !elements.Array[i].Equals(element))
                {
                    element.LessThan(elements.Array[i]);
                    throw new Exception("Ordering violation " + element + "," + elements.Array[i]);
                }
            }

            elements.Add(element);
            precedents.Add(newPrecedents);

            var changes = newPrecedents == 0;

            for (int i = 0; i < Antichain.Count; i++)
            {
                if (element.LessThan(Antichain.Array[i]))
                {
                    changes = true;
                }
            }

            if (changes)
            {
                UpdateAntichain();
            }

            return(changes);
        }
Exemple #4
0
        internal void Release(ref Handle <T> handle)
        {
            FreeList.Add(handle.Descriptor.HeapLocalOffset);

            handle = new Handle <T>();
        }