473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Dictionary data structure

Hello,

I need a kind of lightweight data structure known as "associative array". It
will store a few values that I need to access using textual keys. The
Hashtable is too heavy for me.
I also need to serialize data to Session state or View State (in ASP.NET).

I think there must be a class in .NET I can use. What collection should I
use?

Thanks
Leszek
Nov 16 '05 #1
7 3109
Leszek,

Unfortunately, the Hashtable is going to be your best bet. Unless you
want to code all that searching for indexes and whatnot. What makes it too
"heavy"?

If you are that concerned, then you can use a ListDictionary instance
(in the System.Collections.Specialized namespace), but you will pay for it
in terms of lookup times (because it will iterate through the list, instead
of hashing the keys).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello,

I need a kind of lightweight data structure known as "associative array".
It
will store a few values that I need to access using textual keys. The
Hashtable is too heavy for me.
I also need to serialize data to Session state or View State (in ASP.NET).

I think there must be a class in .NET I can use. What collection should I
use?

Thanks
Leszek

Nov 16 '05 #2
Thank you very much.

Regarding Hashtable I found it cound not be serialized into ASP.NET Session
State. It was a case when I used the State Server process. I did not
investigate this issue, just created a kind of workaroud assuming that
Hashtables are somewhat too complex ("too heavy") for .NET to keep them is
State Server Session. For example strings are kept without any problems
(they are "light").
Now I need to use "associative array" again that's why I am concerned with
"surprises" of Hashtable.

Leszek

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Oj**************@TK2MSFTNGP09.phx.gbl...
Leszek,

Unfortunately, the Hashtable is going to be your best bet. Unless you
want to code all that searching for indexes and whatnot. What makes it too "heavy"?

If you are that concerned, then you can use a ListDictionary instance
(in the System.Collections.Specialized namespace), but you will pay for it
in terms of lookup times (because it will iterate through the list, instead of hashing the keys).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello,

I need a kind of lightweight data structure known as "associative array". It
will store a few values that I need to access using textual keys. The
Hashtable is too heavy for me.
I also need to serialize data to Session state or View State (in ASP.NET).
I think there must be a class in .NET I can use. What collection should I use?

Thanks
Leszek


Nov 16 '05 #3
Leszek Taratuta wrote:
assuming that
Hashtables are somewhat too complex ("too heavy") for .NET to keep them is
State Server Session. For example strings are kept without any problems
(they are "light").


Perhaps you should use the word "unstorable in ASP sessions" to describe
the problem you have with Hashtable, calling it "heavy" mislead (at
least me) to thinking of performance of lookup/insert/remove.

I know nothing of ASP, but couldn't you just inherit from Hashtable and
implement serialization/deserialization yourself?

--
Helge
Nov 16 '05 #4
As a workaround I created my own serializer Hashtable-->String and vice
versa. It works fine for me.
Regarding my original question about "assotiative array" collection in .NET,
I can see that Hashtable is the only viable choice. I mean it is built-in
and ready to use with minimal coding.

So I used Hashtable. It is kept without any problems in APS.NET View State
(I've tested this).

Thanks,
Leszek Taratuta

"Helge Jensen" <he**********@slog.dk> wrote in message
news:#a**************@TK2MSFTNGP09.phx.gbl...
Leszek Taratuta wrote:
assuming that
Hashtables are somewhat too complex ("too heavy") for .NET to keep them is State Server Session. For example strings are kept without any problems
(they are "light").


Perhaps you should use the word "unstorable in ASP sessions" to describe
the problem you have with Hashtable, calling it "heavy" mislead (at
least me) to thinking of performance of lookup/insert/remove.

I know nothing of ASP, but couldn't you just inherit from Hashtable and
implement serialization/deserialization yourself?

--
Helge

Nov 16 '05 #5
Leszek,

You are going to have this problem no matter what data structure you
use. The HashTable is indeed serializable, which means that the error that
you are getting referrs to the fact that something you are placing in the
hashtable is not serializable, not the hashtable itself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Thank you very much.

Regarding Hashtable I found it cound not be serialized into ASP.NET
Session
State. It was a case when I used the State Server process. I did not
investigate this issue, just created a kind of workaroud assuming that
Hashtables are somewhat too complex ("too heavy") for .NET to keep them is
State Server Session. For example strings are kept without any problems
(they are "light").
Now I need to use "associative array" again that's why I am concerned with
"surprises" of Hashtable.

Leszek

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:Oj**************@TK2MSFTNGP09.phx.gbl...
Leszek,

Unfortunately, the Hashtable is going to be your best bet. Unless
you
want to code all that searching for indexes and whatnot. What makes it

too
"heavy"?

If you are that concerned, then you can use a ListDictionary instance
(in the System.Collections.Specialized namespace), but you will pay for
it
in terms of lookup times (because it will iterate through the list,

instead
of hashing the keys).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> Hello,
>
> I need a kind of lightweight data structure known as "associative array". > It
> will store a few values that I need to access using textual keys. The
> Hashtable is too heavy for me.
> I also need to serialize data to Session state or View State (in ASP.NET). >
> I think there must be a class in .NET I can use. What collection should I > use?
>
> Thanks
> Leszek
>
>



Nov 16 '05 #6
That's valuable information.
I am going to check the elements of my Hashtable and find what is not
serializable.

Thanks a lot!

Leszek

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:#u**************@TK2MSFTNGP15.phx.gbl...
Leszek,

You are going to have this problem no matter what data structure you
use. The HashTable is indeed serializable, which means that the error that you are getting referrs to the fact that something you are placing in the
hashtable is not serializable, not the hashtable itself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Thank you very much.

Regarding Hashtable I found it cound not be serialized into ASP.NET
Session
State. It was a case when I used the State Server process. I did not
investigate this issue, just created a kind of workaroud assuming that
Hashtables are somewhat too complex ("too heavy") for .NET to keep them is State Server Session. For example strings are kept without any problems
(they are "light").
Now I need to use "associative array" again that's why I am concerned with "surprises" of Hashtable.

Leszek

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:Oj**************@TK2MSFTNGP09.phx.gbl...
Leszek,

Unfortunately, the Hashtable is going to be your best bet. Unless
you
want to code all that searching for indexes and whatnot. What makes it

too
"heavy"?

If you are that concerned, then you can use a ListDictionary instance (in the System.Collections.Specialized namespace), but you will pay for
it
in terms of lookup times (because it will iterate through the list,

instead
of hashing the keys).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> Hello,
>
> I need a kind of lightweight data structure known as "associative

array".
> It
> will store a few values that I need to access using textual keys. The
> Hashtable is too heavy for me.
> I also need to serialize data to Session state or View State (in

ASP.NET).
>
> I think there must be a class in .NET I can use. What collection
should I
> use?
>
> Thanks
> Leszek
>
>



Nov 16 '05 #7
Nicholas Paldino [.NET/C# MVP] wrote:
The HashTable is indeed serializable

! That surprized me.
Ok, to give some context I am assuming:

==MyClass.cs:
using System;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;

namespace TestHashtableSerialization
{
[XmlRoot(ElementName="MyClass")]
public class MyClass
{
[XmlElement(ElementName="Table")]
public Hashtable table = new Hashtable();

public MyClass()
{ }
}
}
==End of MyClass.cs

==Start.cs (I am skipping the usual code that comes with forms)
using System;
using System.Collections;

using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace TestHashtableSerialization
{
public class Start : System.Windows.Forms.Form
{
public Start()
{
// Required for Windows Form Designer support
InitializeComponent();
}

[STAThread]
static void Main()
{
Application.Run(new Start());
}

private void btn_Test_Click(object sender, System.EventArgs e)
{
try
{
MyClass c = new MyClass();
c.table[0]="zeroth";
c.table[1]="first";

XmlSerializer serializer = new
XmlSerializer(typeof(TestHashtableSerialization.My Class));
TextWriter writer = new StreamWriter("SerializedMyClass.xml");
serializer.Serialize(writer, c);
writer.Close();
MessageBox.Show(this, "MyClass serialized.");
}
catch(Exception e2)
{
MessageBox.Show(this,
"Exception:\n"+e2.ToString());
}
}

}
}

==End of Start.cs

Running this and clicking on the btn_Test button I get an exception:

System.InvalidOperationException: There was an error reflecting type
'TestHashtableSerialization.MyClass'.
---> System.NotSupportedException: The type
System.Collections.Hashtable is not supported because it implements
IDictionary.

So, assuming we were talking about Serialization to Xml files via
XmlSerializer...
....if, as you say, Hashtables ARE Serializable 'out-of-the-box', what
am I missing/doing wrong?

I am *Very Interested*,

thanks,
F.O.R.

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kbass | last post by:
I am new to Python and I am attempting to retrieve data from a database and I would like to place this data into a nested dictionary. After placing the data into a dictionary, I would like to loop...
57
by: Egor Bolonev | last post by:
why functions created with lambda forms cannot contain statements? how to get unnamed function with statements?
7
by: rickle | last post by:
I'm trying to compare sun patch levels on a server to those of what sun is recommending. For those that aren't familiar with sun patch numbering here is a quick run down. A patch number shows...
8
by: Rodd Snook | last post by:
I have an application which makes extensive use of the Scripting.Dictionary object. I'm not doing anything silly like putting them outside the page scope -- just creating quite a few of them and...
0
by: Spur | last post by:
Hi all, Suppose I want to implement a dictionary data structure of some kind, say using a simple BST. I'm wondering how to express the basic operations in the nicest manner. Especially the...
70
by: jojoba | last post by:
Hello! Does anyone know how to find the name of a python data type. Conside a dictionary: Banana = {} Then, how do i ask python for a string representing the name of the above dictionary...
2
by: joe.kimbler | last post by:
What is the best way to handle updates in databases with each release of a software package? I used to work on an accounting package in FoxPro that had a "Data Dictionary" and as your code...
3
by: Jordan | last post by:
I want to store small collections of objects that have a unique id string:"Name", so I opted to use a Dictionary<string,MyObject> collection. However, since my collection will rarely exceed 10 or...
16
by: ravi | last post by:
I want to implement a dictionary data structure with the features features * autocorrect * autocomplete * spellcheck can any body tell me that which data structure will be best for its...
14
by: lee | last post by:
hi, i have a dictionary as follows : kev : {'phno': , 'email': , 'name': , 'address': } if user is enters the 3rd item of key phno, ie "dfsdf" in my dict, how can i find it is the third item...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.