473,748 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hash Table do not contain anything..

Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Hi.. I wrote following code.

Expand|Select|Wrap|Line Numbers
  1. iindex = 0;
  2. foreach (XmlNode Labelnodes1 in Labelnode)
  3. {
  4. countlab = Labelnodes1.Attributes.Count;
  5. for (int i = 0; i < countlab; i++)
  6. {
  7.  
  8. String temp2 = Labelnodes1.Attributes[i].Name;
  9. String temp1 = Labelnodes1.Attributes[i].InnerText;
  10. Proplabval.Add(temp2, temp1);
  11. }
  12. Proptablab.Add(iindex, Proplabval);
  13. Proplabval.Clear();
  14. iindex++;
  15. }
  16.  
I am basically trying to add hash table in hash table.
My for loop(line no 5) will create a hash table.
And it is added to a hash table in for each loop(line no 2)....

Both string temp2,temp1 has correct values..... But when i come out of for each loop my hash table Proptablab do not contain anything....

When i put a break point at line no 12... For all entries it shows the same values.. ie value 1 is same as value2 and equal to value3...
Oct 1 '09 #1
5 2143
PRR
750 Recognized Expert Contributor
You are clearing "Proplabval " line no 13. Debug the code and see if the attributes are added properly ...
Oct 1 '09 #2
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
I took the Hash tables as class members.. When i put them in my member function. The value is persisting when i come out of the code.....

Regards
Dheeraj Joshi
Oct 1 '09 #3
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
You are right... Even i have to comment the clear part......

But another observation.. When it was class member(Hash table)and clear was commented... it was giving same problem.. When i bring it in function and commented clear part, it worked fine..

Regards
Dheeraj Joshi
Oct 1 '09 #4
GaryTexmo
1,501 Recognized Expert Top Contributor
The clear there is correct... and not correct. That is, the idea is right, but the implementation is wrong.

You've actually got two hash tables there, one storing attribute names and values, and another storing that hash table in another hash table using an incrementing value (iindex) as the key.

I see what you're trying to do... you want to make sure you're only adding the attributes for that particular node into Proptablab so you clear Proplabval each time you go through, but what you may not have realized is that almost everything except simple value types (ie, int, float, double, etc...) is a reference type.

So you're throwing Proplabval into Proptablab, then clearing it right after, so you're going to have the empty hash table, which is what you're seeing. What you need to do is create a new hash table for the inner loop... I'll modify your code.

Expand|Select|Wrap|Line Numbers
  1. // This code would have been wherever you defined these two HashTables
  2. HashTable Proptablab = new HashTable();
  3. //HashTable Proplabval = new HashTable(); // Do this in the loop now
  4. ...
  5. iindex = 0;
  6. foreach (XmlNode Labelnodes1 in Labelnode)
  7. {
  8.   HashTable Proplabval = new HashTable();
  9.   countlab = Labelnodes1.Attributes.Count;
  10.   for (int i = 0; i < countlab; i++)
  11.   {
  12.     String temp2 = Labelnodes1.Attributes[i].Name;
  13.     String temp1 = Labelnodes1.Attributes[i].InnerText;
  14.     Proplabval.Add(temp2, temp1);
  15.   }
  16.  
  17.   Proptablab.Add(iindex, Proplabval);
  18.   //Proplabval.Clear(); //This can actually be removed
  19.   iindex++;
  20. }
Give that a try :)
Oct 1 '09 #5
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Hey GaryTexmo....

I already Got the solution.. I did same thing as you told... It is working fine...

Thanks for the inputs....

You are right, i almost forgot about the references... I was so stupid when i coded it...

Regards
Dheeraj Joshi
Oct 1 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4254
by: Pelo GANDO | last post by:
Hi everybody ! I am a beginner in C++. I am looking for a (simple if it's possible) source code in C++ about hash table... Thank you ! Pelo
38
5224
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please let's us do not go into an "each dot over i" clarification discussion now - however you want to call - you call it ;-) array contains records of all files in the current dir. array contains records of all subs in the current dir
12
3204
by: wxs | last post by:
Many times we have a bunch of enums we have from either different enums or the same enum that will have various numeric values assigned. Rarely will there be collisions in numbering between the enums. These enums you might imagine would be like OrderPrice=27, OrderQuantity=50, OrderSide=62. There may be a lot of these. So normally what we would have to do is store these in hash table so hashtable=value could be set with the value....
21
3222
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code (i.e. the get_hash function) is borrowed from various snippets I found on the net. Thee free function could probably need some love. I have been thinking about having a second linked list of all entries so that the cost of freeing is in proportion to...
44
6728
by: gokkog | last post by:
Hi there, There's a classic hash function to hash strings, where MULT is defined as "31": //from programming pearls unsigned int hash(char *ptr) { unsigned int h = 0; unsigned char *p = ptr;
13
2533
by: ababeel | last post by:
Hi I am using a calloc in a hash table program on an openvms system. The calloc is used to declare the hash table char **pHashes; pHashes = calloc(hash_size,sizeof(char *)); //hash_size = 101 and then later on when it is half full i do the following char **newHashes; if(newHashes)
139
14209
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
24
3312
by: Alexander Mahone | last post by:
Hello, I'm looking for an hash function to be used for an hash table that will contain structs of a certain kind. I've looked into Sourceforge.net, but so far I've found only hash functions for strings (string->index)...Do you know if there exist such a function somewhere? Thanks
23
5741
by: raylopez99 | last post by:
A quick sanity check, and I think I am correct, but just to make sure: if you have a bunch of objects that are very much like one another you can uniquely track them simply by using an ArrayList or Array, correct? An example: create the object, create an array, the stuff the object into the array. Later on, assume the object is mutable, the object changes, but you can find it, if you have enough state information to uniquely identify...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9552
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9326
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.