Ejemplo n.º 1
0
        public void SetReturnsCorrectReferencesWhenPeopleAreRemoved()
        {
            ArraySet set = new ArraySet();

            var alice = new Person {
                Name = "Alice"
            };
            var bob = new Person {
                Name = "Bob"
            };
            var charlie = new Person {
                Name = "Charlie"
            };

            set.Add(alice);
            set.Add(bob);
            set.Add(charlie);
            Person[] people = set.GetAllPeople();

            Assert.AreEqual(3, people.Length);
            Assert.IsTrue(people.Contains(alice));
            Assert.IsTrue(people.Contains(bob));
            Assert.IsTrue(people.Contains(charlie));

            set.Remove(bob);
            people = set.GetAllPeople();

            Assert.AreEqual(2, people.Length);
            Assert.IsTrue(people.Contains(alice));
            Assert.IsTrue(people.Contains(charlie));
        }
Ejemplo n.º 2
0
 protected virtual void SetUp()
 {
     set = new ArraySet <int>();
     set.Add(5);
     set.Add(10);
     set.Add(8);
 }
Ejemplo n.º 3
0
        public void AddingAndRemovingPeopleMaintainsCorrectCount()
        {
            ArraySet set = new ArraySet();

            var alice = new Person {
                Name = "Alice"
            };
            var bob = new Person {
                Name = "Bob"
            };
            var charlie = new Person {
                Name = "Charlie"
            };

            Assert.AreEqual(0, set.Count());
            set.Add(alice);
            Assert.AreEqual(1, set.Count());
            set.Add(bob);
            Assert.AreEqual(2, set.Count());
            set.Add(charlie);
            Assert.AreEqual(3, set.Count());

            set.Remove(bob);
            Assert.AreEqual(2, set.Count());
            set.Remove(charlie);
            Assert.AreEqual(1, set.Count());
            set.Remove(alice);
            Assert.AreEqual(0, set.Count());
        }
Ejemplo n.º 4
0
        public void Initialize(ArraySet arraySet, int baseRows, int maximumColumns, Solver solver, int segments)
        {
            this.arraySet = arraySet;
            if (baseRows > arraySet.maxSolverRows || maximumColumns > arraySet.maxSolverCols)
            {
                arraySet.maxSolverRows = Math.Max(baseRows, arraySet.maxSolverRows);
                arraySet.maxSolverCols = Math.Max(maximumColumns, arraySet.maxSolverCols);
                arraySet.RecreateSolverArrays();
            }

            this.solver   = solver;
            this.segments = segments;
            cRows         = baseRows;
            cCols         = 0;

            for (int i = 0; i <= cRows; i++)
            {
                arraySet.rowScale[i] = 1.0;
            }

            if (lp == null)
            {
                lp = new LP(cRows, maximumColumns, arraySet, solver.CalculationOptions.MaxRedecompose);
            }
            else
            {
                lp.Initialize(cRows, maximumColumns, arraySet, solver.CalculationOptions.MaxRedecompose);
            }

            compactSolution = null;
            sort            = null;
            needsDual       = false;
            needsQuadratic  = false;
            maximizeColumn  = -1;
        }
Ejemplo n.º 5
0
        public ICursor FetchAllNotes()
        {
            var repo   = new RemoteRepository();
            var result = repo.GetAllEntries();

            string[] columns = new string[] { "_id", "title", "body" };

            MatrixCursor matrixCursor = new MatrixCursor(columns);

            foreach (var r in result)
            {
                var set = new ArraySet();
                set.Add(r.id);
                set.Add(r.title.ToString());
                set.Add(r.body.ToString());
                matrixCursor.AddRow(set);
            }

            /*var set = new ArraySet();
            *  set.Add("1");
            *  set.Add("ZXC");
            *  set.Add("QWE");
            *
            *  matrixCursor.AddRow(set);
            *  matrixCursor.AddRow(set);*/

            return(matrixCursor);
            //return this.db.Query(DatabaseTable, new[] { KeyRowId, KeyTitle, KeyBody }, null, null, null, null, null);
        }
        private ArraySet UnionAndIntersResult(String posfix)
        {
            Stack <ArraySet> stack = new Stack <ArraySet>();

            foreach (char c in posfix.ToCharArray())
            {
                if (c == 'U' || c == 'u')
                {
                    ArraySet resultTemp = stack.Pop().Union(stack.Pop());
                    stack.Push(resultTemp);
                }
                else if (c == 'n')
                {
                    ArraySet resultTemp = stack.Pop().intersection(stack.Pop());
                    stack.Push(resultTemp);
                }
                else if (c == '-')
                {
                    ArraySet resultTempB = stack.Pop();
                    ArraySet resultTempA = stack.Pop();
                    stack.Push(resultTempA.difference(resultTempB));
                }
                else
                {
                    ArraySet temp1 = setList[getIndexFromChar(c)];
                    stack.Push(temp1);
                }
            }
            return(stack.Pop());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Given a
        /// <c>Tree</c>
        /// node
        /// <paramref name="t"/>
        /// , attempts to
        /// return a list of nodes to which node
        /// <paramref name="t"/>
        /// has this
        /// grammatical relation, with
        /// <paramref name="t"/>
        /// as the governor.
        /// </summary>
        /// <param name="t">Target for finding dependents of t related by this GR</param>
        /// <param name="root">The root of the Tree</param>
        /// <returns>A Collection of dependent nodes to which t bears this GR</returns>
        public virtual ICollection <TreeGraphNode> GetRelatedNodes(TreeGraphNode t, TreeGraphNode root, IHeadFinder headFinder)
        {
            ICollection <TreeGraphNode> nodeList = new ArraySet <TreeGraphNode>();

            foreach (TregexPattern p in targetPatterns)
            {
                // cdm: I deleted: && nodeList.isEmpty()
                // Initialize the TregexMatcher with the HeadFinder so that we
                // can use the same HeadFinder through the entire process of
                // building the dependencies
                TregexMatcher m = p.Matcher(root, headFinder);
                while (m.FindAt(t))
                {
                    TreeGraphNode target = (TreeGraphNode)m.GetNode("target");
                    if (target == null)
                    {
                        throw new AssertionError("Expression has no target: " + p);
                    }
                    nodeList.Add(target);
                    if (Debug)
                    {
                        log.Info("found " + this + "(" + t + "-" + t.HeadWordNode() + ", " + m.GetNode("target") + "-" + ((TreeGraphNode)m.GetNode("target")).HeadWordNode() + ") using pattern " + p);
                        foreach (string nodeName in m.GetNodeNames())
                        {
                            if (nodeName.Equals("target"))
                            {
                                continue;
                            }
                            log.Info("  node " + nodeName + ": " + m.GetNode(nodeName));
                        }
                    }
                }
            }
            return(nodeList);
        }
Ejemplo n.º 8
0
        public void CountMustReturnCorrectValue()
        {
            Assert.AreEqual(setLength, mySet100.Count);

            ArraySet <int>     arrSet = new ArraySet <int>();
            UnmutableSet <int> mySet  = new UnmutableSet <int>(arrSet);

            Assert.AreEqual(0, mySet.Count);
        }
Ejemplo n.º 9
0
        public void CountIsCorrect_1()
        {
            ArraySet set = new ArraySet();

            set.Add(new Person {
                Name = "Alice"
            });

            Assert.AreEqual(1, set.Count());
        }
Ejemplo n.º 10
0
 private void PrepareForScheduling()
 {
     _unfinishedThreadIds          = new ArraySet(_numThreads);
     _waitingThreadIds             = new ArraySet(_numThreads);
     _threadIdsSeenWhileAllWaiting = new ArraySet(_numThreads);
     for (int i = 0; i < _numThreads; ++i)
     {
         _unfinishedThreadIds.Add(i);
     }
 }
Ejemplo n.º 11
0
        public void ConvertAllReturnCorrectValue()
        {
            ArraySet <int> arrSet = new ArraySet <int>();

            arrSet.Add(10);

            Assert.IsInstanceOfType(SetUtils.ConvertAll <int, MySet.HashSet <int> >(arrSet), typeof(MySet.HashSet <int>));
            Assert.IsInstanceOfType(SetUtils.ConvertAll <int, ArraySet <int> >(arrSet), typeof(ArraySet <int>));
            Assert.IsInstanceOfType(SetUtils.ConvertAll <int, LinkedSet <int> >(arrSet), typeof(LinkedSet <int>));
        }
Ejemplo n.º 12
0
        public void Setup()//Подставляет UnmutableSet в mySet перед каждым тестом
        {
            ArraySet <int> arrSet = new ArraySet <int>();

            for (int i = 0; i < setLength; i++)
            {
                arrSet.Add(i);
            }
            mySet100 = new UnmutableSet <int>(arrSet);
        }
Ejemplo n.º 13
0
Archivo: LU.cs Proyecto: rakot/rawr
 public void Initialize(int size, ArraySet arraySet)
 {
     this.size     = size;
     this.arraySet = arraySet;
     etaSize       = 0;
     if (size > arraySet.LUsizeMax)
     {
         arraySet.LUsizeMax = size;
         arraySet.RecreateLUArrays();
     }
 }
Ejemplo n.º 14
0
        public void ExistMustReturnTrueIfItemsExist()
        {
            ArraySet <int> arrSet = new ArraySet <int>();

            arrSet.Add(1);
            arrSet.Add(3);

            Assert.IsTrue(SetUtils.Exists(arrSet, (item) => {
                return(item == 1);
            }));
        }
Ejemplo n.º 15
0
 // data will be modified, if you need to retain it clean pass a clone
 public LU(int size, ArraySet arraySet)
 {
     this.size     = size;
     this.arraySet = arraySet;
     etaSize       = 0;
     if (size > arraySet.LUsizeMax)
     {
         arraySet.LUsizeMax = size;
         arraySet.RecreateArrays();
     }
 }
Ejemplo n.º 16
0
        public void ExistMustReturnFalseIfItemsNonExist()
        {
            ArraySet <int> arrSet = new ArraySet <int>();

            arrSet.Add(1);
            arrSet.Add(3);

            Assert.IsFalse(SetUtils.Exists(arrSet, (item) => {
                return(item == 2);
            }));
        }
Ejemplo n.º 17
0
        public void AddingPersonMultipleTimesDoesNotChangeCount()
        {
            ArraySet set = new ArraySet();

            var alice = new Person {
                Name = "Alice"
            };

            set.Add(alice);
            set.Add(alice);

            Assert.AreEqual(1, set.Count());
        }
Ejemplo n.º 18
0
        public void CountIsCorrect_10K()
        {
            ArraySet set = new ArraySet();

            for (int i = 0; i < 10000; i++)
            {
                set.Add(new Person {
                    Name = $"Alice_{i}"
                });
            }

            Assert.AreEqual(10000, set.Count());
        }
 private void InsertSetButt_Click(object sender, EventArgs e)
 {
     if (setCount < 10 && SetName.Text != "")
     {
         try
         {
             int index = getIndexFromChar(char.Parse(SetName.Text));
             if (index == -1)
             {
                 NotifLabel.Text = "Set Name is Incorrect. try to insert A-J";
                 return;
             }
             ArraySet set = new ArraySet();
             if (setList[index] == null && isCorrectFormat(SetValue.Text))
             {
                 setList[index] = set; //add
                 setCount++;
                 if (!SetValue.Text.Equals(""))
                 {
                     setList[index].addString(SetValue.Text);
                 }
                 NotifLabel.Text = "Insert set " + SetName.Text + " successfully";
                 listBox1.Items.Add(SetName.Text + " : " + set.toString());
                 NotifLabel.ForeColor = Color.Green;
             }
             else if (setList[index] != null)
             {
                 NotifLabel.Text      = "Set " + SetName.Text + " is already exist";
                 NotifLabel.ForeColor = Color.Red;
             }
             else if (!isCorrectFormat(SetValue.Text))
             {
                 NotifLabel.Text      = "Set Element is not in a correct format";
                 NotifLabel.ForeColor = Color.Red;
             }
         }
         catch (Exception)
         {
             NotifLabel.Text = "Incorrect Input";
         }
     }
     else if (setCount >= 10)
     {
         NotifLabel.Text      = "Set is Full";
         NotifLabel.ForeColor = Color.Purple;
     }
     else
     {
         NotifLabel.Text = "Error";
     }
 }
Ejemplo n.º 20
0
        public static void ToList(ArraySet arrset)
        {
            Person[] order = arrset.toSorted();

            Console.Clear();

            foreach (var item in order)
            {
                if (item != null)
                {
                    Console.WriteLine(item);
                }
            }
        }
Ejemplo n.º 21
0
        public void UnionTest()
        {
            for (int i = 0; i < 4; i++)
            {
                set.Add(i);
            }
            ArraySet set1 = new ArraySet();

            for (int i = 2; i < 6; i++)
            {
                set1.Add(i);
            }
            Assert.AreEqual("{2, 3, 4, 5, 0, 1}", set.Union(set1).ToString());
        }
Ejemplo n.º 22
0
        public void DifferenceTest()
        {
            for (int i = 0; i < 4; i++)
            {
                set.Add(i);
            }
            ArraySet set1 = new ArraySet();

            for (int i = 2; i < 6; i++)
            {
                set1.Add(i);
            }
            Assert.AreEqual("{0, 1}", set.Difference(set1).ToString());
        }
Ejemplo n.º 23
0
        public void CheckForAllReturnTrue()
        {
            ArraySet <int> arrSet        = new ArraySet <int>();
            int            numOfElements = 50;

            for (int i = 0; i < numOfElements; i++)
            {
                arrSet.Add(i);
            }

            Assert.IsTrue(SetUtils.CheckForAll <int>(arrSet, (item) => {
                return(item >= 0 && item <= numOfElements);
            }));
        }
Ejemplo n.º 24
0
        public void IntersectionTest()
        {
            for (int i = 0; i < 4; i++)
            {
                set.Add(i);
            }
            ArraySet set1 = new ArraySet();

            for (int i = 2; i < 6; i++)
            {
                set1.Add(i);
            }
            Assert.AreEqual("{2, 3}", set.Intersection(set1).ToString());
        }
Ejemplo n.º 25
0
        public void ConvertAllReturnCorrectNumberOfElements()
        {
            ArraySet <int> arrSet        = new ArraySet <int>();
            int            numOfElements = 50;

            for (int i = 0; i < numOfElements; i++)
            {
                arrSet.Add(i);
            }

            Assert.AreEqual(numOfElements, SetUtils.ConvertAll <int, MySet.HashSet <int> >(arrSet).Count);
            Assert.AreEqual(numOfElements, SetUtils.ConvertAll <int, ArraySet <int> >(arrSet).Count);
            Assert.AreEqual(numOfElements, SetUtils.ConvertAll <int, LinkedSet <int> >(arrSet).Count);
        }
Ejemplo n.º 26
0
    public ArraySet <Pair <T, U> > Cross <U>(ArraySet <U> that)
    {
        ArraySet <Pair <T, U> > result = new ArraySet <Pair <T, U> >();
        int m = this.size;
        int n = that.size;

        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                result.Add(new Pair <T, U>(this.items[i], that.items[j]));
            }
        }
        return(result);
    }
Ejemplo n.º 27
0
        static Person Finder(ArraySet arrset, string id = null)
        {
            if (id == null)
            {
                id = numInput("\nEnter the ID of the record you want:");
            }

            Person person = new Person(id, "", "", 0, "", 0);

            if (arrset.Contains(person))
            {
                int bucket = Math.Abs(person.GetHashCode()) % arrset.Buckets;

                int pos = arrset.BinarySearch(person);

                if (arrset.ArrSet[bucket][pos] != null)
                {
                    person = arrset.ArrSet[bucket][pos];
                    Console.WriteLine(person);
                }
            }

            else
            {
                person.Id = "";

                Console.WriteLine("That record doesn't exist.");
            }

            return(person);

            /* foreach (var item in Person)
             * {
             *
             *  if (item.Id == id)
             *  {
             *
             *      person = item;
             *      Console.WriteLine(person);
             *
             *  }
             *
             * }
             *
             * if (person.Id == "") Console.WriteLine("That record doesn't exist.");
             *
             * return person; */
        }
Ejemplo n.º 28
0
 public static ArraySet RequestArraySet(bool largeArraysHint)
 {
     lock (pool)
     {
         if (pool.Count == 0)
         {
             if (createdArraySets < maximumPoolSize)
             {
                 pool.Add(new ArraySet());
                 createdArraySets++;
             }
             else
             {
                 do
                 {
                     waiters++;
                     Monitor.Wait(pool);
                     waiters--;
                 } while (pool.Count == 0);
             }
         }
         // find desirable size
         int bestIndex;
         if (largeArraysHint)
         {
             bestIndex = 0;
             for (int i = 1; i < pool.Count; i++)
             {
                 if (pool[i].MaxSize > pool[bestIndex].MaxSize)
                 {
                     bestIndex = i;
                 }
             }
         }
         else
         {
             bestIndex = pool.Count - 1;
         }
         ArraySet result = pool[bestIndex];
         result.spellIndex  = 0;
         result.cycleIndex  = 0;
         result.stateIndex  = 0;
         result.effectIndex = 0;
         pool.RemoveAt(bestIndex);
         return(result);
     }
 }
Ejemplo n.º 29
0
        public void Initialize(int rows, int maxCols, ArraySet arraySet)
        {
            this.arraySet = arraySet;
            if (rows > arraySet.SparseMatrixMaxRows || maxCols + 20 > arraySet.SparseMatrixMaxCols)
            {
                arraySet.SparseMatrixMaxRows = Math.Max(rows, arraySet.SparseMatrixMaxRows);
                arraySet.SparseMatrixMaxCols = Math.Max(maxCols + 20, arraySet.SparseMatrixMaxCols); // give some room for AddColumn
                arraySet.RecreateSparseMatrixArrays();
            }
            this.rows = rows;
            this.cols = 0;
            //Array.Clear(data, 0, rows * cols); // only need to clear what will be used

            sparseIndex = 0;
            lastCol     = 0;
            finalized   = false;
        }
Ejemplo n.º 30
0
 public static void ReleaseArraySet(ArraySet arraySet)
 {
     lock (pool)
     {
         if (pool.Count >= maximumPoolSize)
         {
             createdArraySets--;
         }
         else
         {
             pool.Add(arraySet);
             if (waiters > 0)
             {
                 Monitor.Pulse(pool);
             }
         }
     }
 }
 public ExSet()
 {
   s = new ArraySet();
 }
Ejemplo n.º 32
0
        /* hacer un select distinct de un columna pero con DataTable*/
        public System.Collections.ArrayList sacar_val_posibles(System.Data.DataTable dt, string svariable)
        {
            System.Collections.ArrayList alval_pos = new ArrayList();
            if (svariable != null)
            {
                ArraySet asval_pos = new ArraySet();
                int i = 0;

                while (i < dt.Rows.Count)
                {
                    if (dt.Rows[i].RowState != DataRowState.Deleted)
                    {
                        asval_pos.add(dt.Rows[i][svariable].ToString());
                    }
                    i++;
                }

                alval_pos = asval_pos.Source;
            }
            return alval_pos;
        }