Exemplo n.º 1
0
        // return the string representation of the whole
        // tree rooted at this particular node
        //
        public string TreeToString(int sig, MyHashtable nameMap)
        {
            MyHashtable inqueue = new MyHashtable();
            Queue       todo    = new Queue();

            todo.Enqueue(sig);
            StringBuilder result = new StringBuilder();

            while (todo.Count != 0)
            {
                int      nd = (int)todo.Dequeue();
                int      l  = LeftChild(nd);
                int      r  = RightChild(nd);
                NodeType tp = NdType(nd);
                if (tp == NodeType.AND || tp == NodeType.XOR)
                {
                    if (!inqueue.Contains(l))
                    {
                        todo.Enqueue(l);
                        inqueue.Add(l, null);
                    }
                    if (!inqueue.Contains(r))
                    {
                        todo.Enqueue(r);
                        inqueue.Add(r, null);
                    }
                }
                result.Append(ToString(nd, nameMap));
            }
            return(result.ToString());
        }
Exemplo n.º 2
0
        public void MyHashtable_Add5_succeeds()
        {
            var hashtbl = new MyHashtable <string, Person>(10);
            var p       = new Person()
            {
                Name = "Louise", City = "Dublin"
            };
            var p2 = new Person()
            {
                Name = "Mary", City = "Dublin"
            };
            var p3 = new Person()
            {
                Name = "John", City = "Dublin"
            };
            var p4 = new Person()
            {
                Name = "Louise", City = "Cork"
            };
            var p5 = new Person()
            {
                Name = "Gary", City = "Galway"
            };

            hashtbl.Add(p.Name, p);
            hashtbl.Add(p2.Name, p2);
            hashtbl.Add(p3.Name, p3);
            hashtbl.Add(p4.Name, p4);
            hashtbl.Add(p5.Name, p5);

            Assert.AreEqual(hashtbl.Count(), 5);
        }
Exemplo n.º 3
0
    //</Snippet2>

    static void Main()
    {
        MyHashtable myHashTable = new MyHashtable();

        myHashTable.Add("one", 1);
        myHashTable.Add("two", 2);
        Console.WriteLine(myHashTable.ToString());
        Console.WriteLine("In Main.");
    }
Exemplo n.º 4
0
        public void TestForCollisonOfHashKeys1()
        {
            MyHashtable test3 = new MyHashtable();

            test3.Add("Cat", 1);
            test3.Add("Cat", 2);
            test3.Add("Doe", 3);
            test3.Add("Doe", 4);

            Assert.Equal(163, test3.GetHash("Cat"));
            Assert.Equal(163, test3.GetHash("Doe"));
        }
Exemplo n.º 5
0
        public void TestForContainMethodOfHash()
        {
            MyHashtable test2 = new MyHashtable();

            test2.Add("test", 1);
            test2.Add("test", 2);
            test2.Add("test2", 3);
            test2.Add("test2", 4);

            Assert.True(test2.Contains("test"));
            Assert.True(test2.Contains("test2"));
            Assert.False(test2.Contains("test1"));
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var hash = new MyHashtable();

            hash.Add(1, 2);
            Debugger.Break();
        }
Exemplo n.º 7
0
        public void TestForAddingValuesToHash()
        {
            MyHashtable test1 = new MyHashtable();

            test1.Add("test", 1);
            test1.Add("test", 2);
            test1.Add("test", 3);
            test1.Add("test", 4);

            List <int> result = test1.Find("test");
            List <int> expect = new List <int> {
                1, 2, 3, 4
            };

            Assert.Equal(expect, result);
        }
Exemplo n.º 8
0
        public void MyHashtable_Add2_succeeds()
        {
            var hashtbl = new MyHashtable <string, Person>(10);
            var p       = new Person()
            {
                Name = "Louise", City = "Dublin"
            };
            var p2 = new Person()
            {
                Name = "Mary", City = "Dublin"
            };

            hashtbl.Add(p.Name, p);
            hashtbl.Add(p2.Name, p2);

            Assert.AreEqual(hashtbl.Count(), 2);
        }
Exemplo n.º 9
0
        public void MyHashtable(int[] items, int capacity)
        {
            var hashtable = new MyHashtable <int>(capacity);

            for (int i = 0; i < items.Length; i++)
            {
                hashtable.Add($"item {items[i]}", items[i]);
            }
        }
Exemplo n.º 10
0
        public void TestForCollisionOfHashKeys2()
        {
            MyHashtable test3 = new MyHashtable();

            test3.Add("Cat", 1);
            test3.Add("Cat", 2);
            test3.Add("Doe", 3);
            test3.Add("Doe", 4);

            List <int> catValueList = test3.Find("Cat");
            List <int> doeValueList = test3.Find("Doe");
            List <int> expected     = new List <int> {
                1, 2, 3, 4
            };

            Assert.Equal(expected, catValueList);
            Assert.Equal(expected, doeValueList);
        }
Exemplo n.º 11
0
        // this demonstrate the structure interface
        static void test_structure_solver(string[] args)
        {
            SATSolver solver = new SATSolver();
            int       a      = solver.CreatePI();
            int       b      = solver.CreatePI();
            int       c      = solver.CreatePI();
            //int d = solver.CreatePI();
            int       xor_a_b     = solver.Xor(a, b);
            int       not_a       = solver.Not(a);
            int       not_b       = solver.Not(b);
            int       and_a_not_b = solver.And(a, not_b);
            int       and_b_not_a = solver.And(b, not_a);
            int       xor_a_b_p   = solver.Or(and_a_not_b, and_b_not_a);
            int       miter       = solver.Xor(xor_a_b, xor_a_b_p);
            SATStatus r           = solver.TestSAT(miter);

            WriteLine(String.Format("Test Right {0}", r.ToString()));

            int and_a_b       = solver.And(a, b);
            int xor_a_b_wrong = solver.Or(and_a_not_b, and_a_b);
            int miter1        = solver.Xor(xor_a_b, xor_a_b_wrong);

            r = solver.TestSAT(miter1);
            WriteLine(String.Format("Test Wrong {0}", r.ToString()));

            int and_a_b_c = solver.And(solver.And(a, b), c);

            int flag = solver.AllocFlag();

            solver.MarkTransitiveFanins(and_a_b_c, flag);
            for (int i = 0, sz = solver.NumPI(); i < sz; ++i)
            {
                int  node_id = solver.NthPI(i);
                bool flagset = solver.IsNodeFlagSet(node_id, flag);
                if (flagset)
                {
                    WriteLine(String.Format("PI {0} is in the transitive fanin", i));
                }
                else
                {
                    WriteLine(String.Format("PI {0} is NOT in the transitive fanin", i));
                }
            }
            solver.ClearFlag(flag);


            MyHashtable nameMap = new MyHashtable();

            nameMap.Add(0, "PrimaryIn 0");
            WriteLine(solver.TreeToString(miter1, nameMap));
            WriteLine(solver.TreeToString(xor_a_b, nameMap));

            WriteLine("Press Return...");
            System.Console.ReadLine();
        }
Exemplo n.º 12
0
        public void MyHashtable_Add2SameKey_Find1_succeeds()
        {
            var hashtbl = new MyHashtable <string, Person>(10);
            var p       = new Person()
            {
                Name = "Louise", City = "Dublin"
            };
            var p2 = new Person()
            {
                Name = "Louise", City = "Cork"
            };

            hashtbl.Add(p.Name, p);
            hashtbl.Add(p2.Name, p2);

            var result = hashtbl.Find(p2.Name);

            Assert.AreEqual(result.City, p.City);
            Assert.AreEqual(result.Name, p.Name);
        }
Exemplo n.º 13
0
        public MyHashtable generate_unsat_core()
        {
            if (empty == null)
            {
                fatal("Not UNSAT, Cannot Generate Core");
            }

            MyHashtable hash = new MyHashtable();

            foreach (int uid in empty.reasons)
            {
                hash.Add(uid, null);
            }

            long oldpos = storage.Position;

            storage.Seek(0, SeekOrigin.End);
            while (storage.Position > 0)
            {
                ResolveNode nd = ResolveNode.DeSerializeBackward(storage);
                sharp_assert(!is_node(nd.uid));
                if (hash.Contains(nd.uid))
                {
                    foreach (int id in nd.reasons)
                    {
                        int uid = id;
                        if (is_node(id))
                        {
                            uid = node_uid(id);
                        }
                        if (!hash.Contains(uid))
                        {
                            hash.Add(uid, null);
                        }
                    }
                    hash.Remove(nd.uid);
                }
            }
            storage.Seek(oldpos, SeekOrigin.Begin);
            return(hash);
        }
Exemplo n.º 14
0
        private void buttonAgregarVenta_Click(object sender, EventArgs e)
        {
            var clienteNit = (comboBoxAgregarVentaCliente.SelectedItem ?? "").ToString();

            if (clienteNit.IsEmpty())
            {
                MessageBox.Show("Datos no validos");
                return;
            }

            var cliente = Clientes.Get(new Cliente(clienteNit));

            if (cliente == null)
            {
                MessageBox.Show("No existe ese cliente");
                MessageBox.Show("No existe ese cliente");
                return;
            }

            var date = monthCalendar1.SelectionRange.Start;

            if (date == null)
            {
                date = DateTime.Today;
            }

            VentaActual.Fecha   = date;
            VentaActual.Cliente = cliente;

            var ventaId = new MyString(CuentaDeVentas.ToString());

            Ventas.Add(ventaId, VentaActual);
            CuentaDeVentas++;

            ActualizarVistaPrevia();
            MessageBox.Show("Se agrego la venta exitosamente");
            VentaActual = new Venta();
        }
Exemplo n.º 15
0
        MyHashtable find_all_involved()
        {
            if (empty == null)
            {
                fatal("Not UNSAT, Cannot Generate Core");
            }

            MyHashtable hash = new MyHashtable();

            foreach (int uid in empty.reasons)
            {
                hash.Add(uid, 1);
            }

            long oldpos = storage.Position;

            storage.Seek(0, SeekOrigin.End);
            while (storage.Position > 0)
            {
                ResolveNode nd = ResolveNode.DeSerializeBackward(storage);
                if (hash.Contains(nd.uid))
                {
                    foreach (int uid in nd.reasons)
                    {
                        if (!hash.Contains(uid))
                        {
                            hash[uid] = 1;
                        }
                        else
                        {
                            hash[uid] = (int)hash[uid] + 1;
                        }
                    }
                }
            }
            storage.Seek(oldpos, SeekOrigin.Begin);
            return(hash);
        }
        static void Main(string[] args)
        {
            MyHashtable ht = new MyHashtable();

            ht.Add("one", 5);
            Console.WriteLine("Added => Key: one, value: 5 ");

            ht.Add("one", 15);
            Console.WriteLine("Added => Key: one, value: 15 ");

            ht.Add("two", 10);
            Console.WriteLine("Added => Key: two, value: 10 ");
            Console.WriteLine();

            List <int> valueList = ht.Find("one");

            Console.WriteLine("Key of 'one' contains following values: ");
            foreach (int val in valueList)
            {
                Console.WriteLine(val);
            }
            Console.WriteLine();
            bool contain  = ht.Contains("one");
            bool contains = ht.Contains("One");

            Console.WriteLine();
            Console.WriteLine("Hastable contains a key of 'one': " + contain);
            Console.WriteLine("Hastable contains a key of 'One': " + contains);
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Collision test of 'Cat' and 'Doe' : ");
            Console.WriteLine();

            MyHashtable colsn = new MyHashtable();

            colsn.Add("Cat", 50);
            Console.WriteLine("Added => Key: Cat, value: 50 ");
            colsn.Add("Doe", 100);
            Console.WriteLine("Added => Key: Doe, value: 100 ");

            List <int> catList = colsn.Find("Cat");
            List <int> doeList = colsn.Find("Doe");

            Console.WriteLine("Key: Cat holds following value(s): ");
            foreach (int i in catList)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine();
            Console.WriteLine("Key: Doe holds following value(s);");
            foreach (int i in doeList)
            {
                Console.WriteLine(i);
            }

            Console.WriteLine();
            bool containCat = colsn.Contains("Cat");
            bool containDoe = colsn.Contains("Doe");

            Console.WriteLine();
            Console.WriteLine("Hastable contains a key of 'Cat': " + containCat);
            Console.WriteLine("Hastable contains a key of 'Doe': " + containDoe);
        }