Ejemplo n.º 1
0
        public void Union(int indexA, int indexB)
        {
            int rootIndexA = FindRootIndex(indexA);
            int rootIndexB = FindRootIndex(indexB);

            if (rootIndexA != rootIndexB)
            {
                // A and B are not in the same set, merge them
                if (m_set[rootIndexA].rank < m_set[rootIndexB].rank)
                {
                    SetEntry entryA = m_set[rootIndexA];

                    entryA.parent_index = rootIndexB;
                }
                else if (m_set[rootIndexA].rank > m_set[rootIndexB].rank)
                {
                    SetEntry entryB = m_set[rootIndexB];

                    entryB.parent_index = rootIndexA;
                }
                else
                {
                    SetEntry entryA = m_set[rootIndexA];
                    SetEntry entryB = m_set[rootIndexB];

                    entryB.parent_index = rootIndexA;
                    entryA.rank++;
                }
            }
        }
Ejemplo n.º 2
0
        public int FindRootIndex(int index)
        {
            if (index != m_set[index].parent_index)
            {
                SetEntry setEntry = m_set[index];

                setEntry.parent_index = FindRootIndex(m_set[index].parent_index);
            }

            return(m_set[index].parent_index);
        }
Ejemplo n.º 3
0
        public void AddElement(T payload)
        {
            // Keep a mapping of where a given payload exists in the UnionFind
            m_payloadToIndexMap.Add(payload, m_set.Count);

            // Add the payload to the set
            {
                SetEntry newEntry = new SetEntry();

                newEntry.parent_index = m_set.Count;
                newEntry.rank         = 0;
                newEntry.payload      = payload;

                m_set.Add(newEntry);
            }
        }
Ejemplo n.º 4
0
        protected static SetEntry Except(SetEntry setEntry)
        {
            var listRanges = new List <RangeEntry>();
            var current    = char.MinValue;

            foreach (var entry in setEntry.Matches.OrderBy(GetMinChar))
            {
                if (entry is RangeEntry range)
                {
                    if (range.First > current)
                    {
                        var next = (char)(range.First - 1);

                        if (current < next)
                        {
                            listRanges.Add(new RangeEntry(current, next));
                        }
                    }

                    current = (char)(range.Last + 1);

                    continue;
                }

                var charEntry = (CharEntry)entry;
                var prev      = (char)(charEntry.Char - 1);

                if (current < prev)
                {
                    listRanges.Add(new RangeEntry(current, prev));
                }

                current = (char)(charEntry.Char + 1);
            }

            if (current < char.MaxValue)
            {
                listRanges.Add(new RangeEntry(current, char.MaxValue));
            }

            return(new SetEntry(listRanges));
        }
Ejemplo n.º 5
0
        public object Any(SetEntry request)
        {
            Redis.SetValue(request.Key, request.Value);

            return(new SetEntryResponse());
        }
Ejemplo n.º 6
0
 internal CallbackReference(VariableName originatedVar, GetEntry getter, SetEntry setter)
     : base(originatedVar, VariableKind.Meta, -1)
 {
     _getter = getter;
     _setter = setter;
 }