Ejemplo n.º 1
0
        public HashTable(int ll, HashFuncType hashfunction)
        {
            func = hashfunction;

            l = ll;

            var uni = Math.Pow(2, l);

            // here we create an empty list of lists
            hashT = new List <List <MutableKeyValuePair <int, int> > >();

            for (int i = 0; i < uni; i++)
            {
                hashT.Add(new List <MutableKeyValuePair <int, int> >());
            }
        }
Ejemplo n.º 2
0
        static UInt64 SFunc(IEnumerable <Tuple <ulong, int> > stream, int l, HashFuncType funcType)
        {
            // we begin by storing the key value pairs in the hash table using the hashfunctions
            HashTable hashTable = new HashTable(l, funcType);
            // the loop below computes s(x)
            var watch = new Stopwatch();

            watch.Start();
            foreach (Tuple <ulong, int> pair in stream)
            {
                if (hashTable.get(pair.Item1) == 0)              // key does not exist
                {
                    hashTable.set(pair.Item1, pair.Item2);       // put key value pair in hashtable
                }
                else                                             // key exists
                {
                    hashTable.increment(pair.Item1, pair.Item2); // add value to already existing key value
                }
            }
            watch.Stop();
            Console.WriteLine("Hashing to table took " + watch.ElapsedMilliseconds + "ms.");

            watch.Reset();
            watch.Start();
            // next we add the s(x)^2 above to compute S, as required
            UInt64 sum = 0UL;

            foreach (List <MutableKeyValuePair <int, int> > lst in hashTable.hashT)
            {
                foreach (MutableKeyValuePair <int, int> pair in lst)
                {
                    sum += (ulong)Math.Pow(pair.Value, 2);
                }
            }
            watch.Stop();
            Console.WriteLine("Calculating S took " + watch.ElapsedMilliseconds + "ms.");

            Console.WriteLine("S is:" + sum);
            return(sum);
        }
Ejemplo n.º 3
0
        static void Exercise3(HashFuncType type)
        {
            Console.WriteLine("type: " + type + "\nn=1,000,000" + "\n___________");
            // l=1 .. 25
            // n=1000000

            int        n     = 1000000;
            List <int> llist = new List <int> {
                5, 10, 15, 20, 25
            };
            var watch = new Stopwatch();


            foreach (int lval in llist)
            {
                Console.WriteLine("l-value: " + lval);
                watch.Start();
                SFunc(Generator.CreateStream(n, lval), lval, type);
                watch.Stop();
                Console.WriteLine("total time: " + watch.ElapsedMilliseconds);
                Console.WriteLine();
                watch.Reset();
            }
        }