[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.7

Custom Hashtable C#

Asked by CallConnection in C# Programming Language, Microsoft Visual C#.Net, Programming Languages

Tags: .Net, C#, Hashtable implementation, Custom Hashtable

Hello Experts!

I would like to reasonably quickly lookup objects by NON-UNIQUE values in a collection.

Naturally I tried at Hashtables and Dictionaries, but because they rely on key's uniqueness, I couldn't really use them.

&By the way, if you know an alternative way, I don't mind what "collection" to use.  Any collection that would be quick for storing extra large collection (1 million objects), and looking them up. The type of each VALUE to lookup is long.

Hence the idea of custom Hashtable..  I thought of implementing a custom hashable solution which would in effect use chaining and not rehashing (http://en.wikipedia.org/wiki/Hash_table)

I wanted to ask if you know of a good (fast!?) implementation of this, or if not, if you could look at my code and suggest how it can be improved/completed please?

If you think it's a good idea, how would you implement the rest?

It implements just one nonunique key lookup (but there may be more).



Thank you,
Dmitri
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
// ************************************************************
//  This is just a section which is supposed to generate the "CustomHash" collection.
//
// The general idea is that you'd follow this path to get back an object:
// HashListHeader  ->  Bucket_keys -> BucketObjects
// By the way, I have been using the following to test the speed of this block:
/*
            public static System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch();
            s.Reset();
            s.Start();
            for (int i = 0; i < 10; i++)
            {
                HashListOfLists(1000000);
                
            }
            s.Stop();
            textBox1.Text += ("result = " + s.Elapsed + Environment.NewLine);
*/
// ************************************************************
 
        // 4294967298 - the value required to get hash int from hash long  (you can also get it by maxlong / maxint!)
        // 7700 - trial and error figure - seems to provide optimum balance for hash collisions, between the length of collision list and length of hash list
        static long long2int_denominator = (4294967298 * 7700);
 
        public static int GetNewArraySize(int OldSize, int nextIndex)
        {
            double incrementer = 0.0;
            if (OldSize < 100) incrementer = 2;
            else incrementer = 1.5;
 
            int newSize = (int)((double)OldSize + ((double)OldSize * incrementer));
 
            if (nextIndex >= newSize)
            {
                newSize = (int)((double)nextIndex + ((double)nextIndex * incrementer));
            }
            return newSize;
        }
 
        public static void HashListOfLists(int new_terations)
        {
            int[] HashListHeader = new int[278894];  // the size of this would never go higher than 278894
                                                                               // because 2147483647 (aka int!) / 7700 = 278893
                                                                               // see long2int_denominator defenition...
            List<List<long>> Bucket_keys = new List<List<long>>();
            List<List<string>> Bucket_objects = new List<List<string>>();   // to be replaced with the object...
            
            //populate the list with new lists.
            int while_loop1 = 0;
            while (while_loop1 < new_terations)
            {
                Bucket_keys.Add(new List<long>());
                Bucket_objects.Add(new List<string>());
                while_loop1++;
            }
 
            Random r = new Random();
            int current_list;           // create some random stuff to test this
            long value;
            int int_hash_value;
            for (int i = 0; i < new_terations; i++)
            {
                value = (long)((r.NextDouble() * 2.0 - 1.0) * long.MaxValue);  // create some random value to test
                int_hash_value = (int)(Math.Abs(value) / long2int_denominator); // get the hashed value ready to be inserted into the hash list header.
 
                current_list = HashListHeader[int_hash_value];
                if (current_list == null || current_list == 0)
                {
                    HashListHeader[int_hash_value] = i;
                    current_list = i;
                }
                Bucket_objects[current_list].Add(i.ToString());
                Bucket_keys[current_list].Add(value);
            }
        }
[+][-]05/06/09 08:46 AM, ID: 24316210Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C# Programming Language, Microsoft Visual C#.Net, Programming Languages
Tags: .Net, C#, Hashtable implementation, Custom Hashtable
Sign Up Now!
Solution Provided By: gregoryyoung
Participating Experts: 3
Solution Grade: A
 
[+][-]04/29/09 04:39 AM, ID: 24259231Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/29/09 04:45 AM, ID: 24259282Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/29/09 05:00 AM, ID: 24259392Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/29/09 05:07 AM, ID: 24259450Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/29/09 06:27 AM, ID: 24260152Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/29/09 09:15 AM, ID: 24262024Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/29/09 09:22 AM, ID: 24262106Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/29/09 10:04 AM, ID: 24262473Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/29/09 01:14 PM, ID: 24264280Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/30/09 03:18 PM, ID: 24274942Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/06/09 08:25 AM, ID: 24315921Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/06/09 08:27 AM, ID: 24315959Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/06/09 11:33 AM, ID: 24318079Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/06/09 01:55 PM, ID: 24319562Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/06/09 02:01 PM, ID: 24319636Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/07/09 08:32 AM, ID: 24327002Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/07/09 08:40 AM, ID: 24327085Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/07/09 09:30 AM, ID: 24327632Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/08/09 07:11 AM, ID: 24336210Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/08/09 08:24 AM, ID: 24336968Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625