473,750 Members | 6,086 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

3-D String Array (or better alternative?)

I have data that looks something like this when returned from a stored
procedure (3 columns, X rows):

Key1 Name1 Value1
Key1 Name2 Value2
Key1 Name3 Value3
Key1 Name4 Value4
Key2 Name1 Value1
Key2 Name2 Value2
Key3 Name1 Value1
KeyX NameY ValueY

Data type for all is string.
Number of rows returned from sp will never exceed 100.

You can see that there is a conceptual 1:many relationship between Keys and
Names; and a 1:1 relationship between Names and Values.

Order for Key, Name, or Value is unimportant to my application logic - so
could be returned from db sorted by alpha if necessary.

My application logic needs to (1) quickly find all of the Name/Value pairs
for a given key; and (2) update specific Value values (sorry!). Eventually
all the updated Value values will be written back to the database (i.e.,
Keys and Names will never be updated) The application logic will never add
or remove Keys, Names, or Values. We're only reading lists of Name/Value
pairs, and updating Value values.

I would prefer to *not* store this in an in-memory ADO.NET DataTable for
performance and size reasons.

I'm thinking a 3-dimensional array might give me best performance - but I
don't know the syntax required to populate it or to retrieve and update its
data. I could look it up, but don't know if doing that would yield the best
performance.

Recommendations ? Suggestions? (syntax examples, if possible, would be very
much appreciated).

Thank You!
Nov 16 '05 #1
6 3542
You can do this with 2 System.Collecti ons.Hashtable(s ) ala:

HashTable<key, hashTable>
HashTable<name, value>

1st table holds key values and references to name/value pair hash for each key... FYI .NET configuration file info is stored in memory in Hashtables as string keys with to object or Hashtable values; Hashtable values store string keys with object or Hashtable values, and so on, and so on...

--OR--

You can take advantage of 1:1 between Name & Value and use only 1 hashtable ala:

HashTable<key + name, value> keyNameValuePai rs;

When inserting into Hash literally use "key + name" as the key. Substring can be used to seperate "key + name" back into 2 pieces if needed.

--Richard

"Doug" wrote:
I have data that looks something like this when returned from a stored
procedure (3 columns, X rows):

Key1 Name1 Value1
Key1 Name2 Value2
Key1 Name3 Value3
Key1 Name4 Value4
Key2 Name1 Value1
Key2 Name2 Value2
Key3 Name1 Value1
KeyX NameY ValueY

Data type for all is string.
Number of rows returned from sp will never exceed 100.

You can see that there is a conceptual 1:many relationship between Keys and
Names; and a 1:1 relationship between Names and Values.

Order for Key, Name, or Value is unimportant to my application logic - so
could be returned from db sorted by alpha if necessary.

My application logic needs to (1) quickly find all of the Name/Value pairs
for a given key; and (2) update specific Value values (sorry!). Eventually
all the updated Value values will be written back to the database (i.e.,
Keys and Names will never be updated) The application logic will never add
or remove Keys, Names, or Values. We're only reading lists of Name/Value
pairs, and updating Value values.

I would prefer to *not* store this in an in-memory ADO.NET DataTable for
performance and size reasons.

I'm thinking a 3-dimensional array might give me best performance - but I
don't know the syntax required to populate it or to retrieve and update its
data. I could look it up, but don't know if doing that would yield the best
performance.

Recommendations ? Suggestions? (syntax examples, if possible, would be very
much appreciated).

Thank You!

Nov 16 '05 #2

"Doug" <Cl******@Liver more.com> wrote in message
news:OB******** ******@TK2MSFTN GP09.phx.gbl...
I have data that looks something like this when returned from a stored
procedure (3 columns, X rows):

Key1 Name1 Value1
Key1 Name2 Value2
Key1 Name3 Value3
Key1 Name4 Value4
Key2 Name1 Value1
Key2 Name2 Value2
Key3 Name1 Value1
KeyX NameY ValueY

Data type for all is string.
Number of rows returned from sp will never exceed 100.
.... I would prefer to *not* store this in an in-memory ADO.NET DataTable for
performance and size reasons.


....

These two statements are inconsistent. With fewer than 100 rows, you can
have no valid objection to using a DataTable.

That being said you could load these items into a hashtable. The key here
is that the hashtable entries would be collections. SOmething like this:
Hashtable ht = new Hashtable();
IDictionary keyItems;
if (!ht.Contains(k eyName))
{
keyItems = new System.Collecti ons.Specialized .ListDictionary ();
ht.Add(keyName, keyItems);
}
else
{
keyItems = (IDictionary) ht[keyName];
}
keyItems.Add(na me,value);
Here using a Hashtable for the outer dictionary and a linked list for the
inner one.

David
Nov 16 '05 #3
<<With fewer than 100 rows, you can have no valid objection to using a
DataTable>>

There might be this objection given the context in which this thing will be
used: The context is that this structure (whatever I end up with) will exist
in an ASP.NET Web Application Session state. So, start multiplying the
"fewer than 100 rows" by the number of Sessions and suddenly size matters
more and more as the number of Sessions increases.

Perhaps I'm still wrong though. The unnecessary size I'm thinking of is the
XML involved in storing this as a DataTable (I haven't measured the bytes
involved, but we all know XML is verbose - more so than a 3d array or
Hashtable - and DataTables are XML structures.).

Thanks for the sample code on the Hashtable.
Nov 16 '05 #4
Not sure why it hasn't been offered but the HybridDictionar y is a great space
saving device that switches from using an internal array and linear look-up to
using a Hashtable at a predefined performance tuned size. The class was
specifically built to improve performance of look-up and memory usage when
using lightly populated collections of name/value pairs. In context this would
automatically switch you to the most performant method depending on the
numbers of records rather than requiring large amounts of code.

To speak in the defense of the DataSet, it doesn't use XML until you serialize
it. You aren't wasting memory by using a DataSet at all. There is some small
extra overhead in using it because of extra properties about the data that are
stored but in general all you have is:

A DataSet, and you don't even have that unless you want one.
A DataTable - DataColumnColle ction and DataRowCollecti on
DataColumnColle ction - Consists of DataColumn's one for each
DataRowCollecti on - Consists of DataRow's one for each row

DataRow - int's that offset into DataStorage. Doesn't store values
DataColumn - Information about the actual column + a DataStorage element
that allows indexing by the DataRow into the internal storage.
StringStorage is the DataStorage override used and it has a string[] backing
store.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Doug" <Cl******@Liver more.com> wrote in message
news:eC******** ******@TK2MSFTN GP09.phx.gbl...
<<With fewer than 100 rows, you can have no valid objection to using a
DataTable>>

There might be this objection given the context in which this thing will be
used: The context is that this structure (whatever I end up with) will exist
in an ASP.NET Web Application Session state. So, start multiplying the
"fewer than 100 rows" by the number of Sessions and suddenly size matters
more and more as the number of Sessions increases.

Perhaps I'm still wrong though. The unnecessary size I'm thinking of is the
XML involved in storing this as a DataTable (I haven't measured the bytes
involved, but we all know XML is verbose - more so than a 3d array or
Hashtable - and DataTables are XML structures.).

Thanks for the sample code on the Hashtable.

Nov 16 '05 #5
A 1:many relationship between Keys and Values? Then you cannot use a
Hasthtable or HybridDictionar y. A key needs to reference one and only one
value, and it must be unique in the collection (no duplicates as in your
example data).

For 100 entries use a DataTable. You can then use the DefaultView to Filter
and/or Find the rows you need.

kevin aubuchon
"Doug" <Cl******@Liver more.com> wrote in message
news:OB******** ******@TK2MSFTN GP09.phx.gbl...
I have data that looks something like this when returned from a stored
procedure (3 columns, X rows):

Key1 Name1 Value1
Key1 Name2 Value2
Key1 Name3 Value3
Key1 Name4 Value4
Key2 Name1 Value1
Key2 Name2 Value2
Key3 Name1 Value1
KeyX NameY ValueY

Data type for all is string.
Number of rows returned from sp will never exceed 100.

You can see that there is a conceptual 1:many relationship between Keys and Names; and a 1:1 relationship between Names and Values.

Order for Key, Name, or Value is unimportant to my application logic - so
could be returned from db sorted by alpha if necessary.

My application logic needs to (1) quickly find all of the Name/Value pairs
for a given key; and (2) update specific Value values (sorry!). Eventually
all the updated Value values will be written back to the database (i.e.,
Keys and Names will never be updated) The application logic will never add
or remove Keys, Names, or Values. We're only reading lists of Name/Value
pairs, and updating Value values.

I would prefer to *not* store this in an in-memory ADO.NET DataTable for
performance and size reasons.

I'm thinking a 3-dimensional array might give me best performance - but I
don't know the syntax required to populate it or to retrieve and update its data. I could look it up, but don't know if doing that would yield the best performance.

Recommendations ? Suggestions? (syntax examples, if possible, would be very
much appreciated).

Thank You!

Nov 16 '05 #6
Kevin Aubuchon <ke************ @sbcglobal.net> wrote:
A 1:many relationship between Keys and Values? Then you cannot use a
Hasthtable or HybridDictionar y. A key needs to reference one and only one
value, and it must be unique in the collection (no duplicates as in your
example data).


There's nothing to stop you from using Hashtable even so - just make
the value set in the hashtable be a reference to an ArrayList
containing all the entries for that key.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7

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

Similar topics

51
8285
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct code? many thx!
6
20776
by: andrewcw | last post by:
The split function takes as a parameter what I understand as array of Char. I can define the delimiter like this: string innerText = new string; char chSplit={'='}; innerText=tempText.Split(chSplit); But if I try this ( to make the delimiter a variable ):
6
8960
by: Jozef Jarosciak | last post by:
Quickest way to find the string in 1 dimensional string array! I have a queue 1 dimensional array of strings called 'queue' and I need a fast way to search it. Once there is match, I don't need to search any longer. Currently I am using this code. But I think it's too slow, because it runs through whole dimension. I know this is trivial question, but is there any way to stop this loop, or better way to search? I mean - FASTER?
23
2492
by: mrvendetta1 | last post by:
#include <stdio.h> #include <string.h> #include <stdlib.h> #define N 33 void StringToIntArray(const char *s1); void takeinteger(int i); int main() { char string; printf("enter a string of bits no more than 32 bits long: ");
10
6185
by: zahy[dot]bnaya[At]gmail[dot]com | last post by:
Hi, I am trying to come up with a c style string reverser, I want it to take 1 argument Altough I would never do this in real life. Is there a way to do it? I wrote this function that fails : Any idea why it fails? char * C_recReverse(char * str)
7
8583
by: Felix85 | last post by:
I am trying to make a command interpreter for a mud that i am working on the problem i am having right now is that i cannot convert the string into a char array. This is the error I am getting now: In file included from src/mud.cpp:3: src/command.h: In static member function `static void command::getCommand(std::string)': src/command.h:38: error: incompatible types in assignment of `const
7
1868
by: lovecreatesbea... | last post by:
K&R 2, sec. 5.11 says that no need to precede function and array names with address-of operators &, why?
14
1770
by: aqazi | last post by:
Hi folks I am trying to write a program which acts like a p2p server. When the program starts it reads a file from whereit will read broadcast IP address, port and another port number. Now I am trying skip the comments and empty lines by saying if there is newline or # sign at the first charecter of a line then to skip the line.But the problem is the program is not working. I am using the following code:
6
3869
by: Arnshea | last post by:
(apologies for the crosspost) I'm working with an MFC based COM object. From C# I'd like to be able to call a method on the COM object that takes a string array and modifies the contents. Is there any way to do this with a variable length array? I've only been able to get it to work with a fixed size array. The relevant code snippets are below. Suggestions are greatly appreciated
2
2250
by: Bart Kastermans | last post by:
Summary: can't verify big O claim, how to properly time this? On Jun 15, 2:34 pm, "Terry Reedy" <tjre...@udel.eduwrote: Thanks for the idea. I would expect the separation to lead to somewhat more code, but all the "checking the root" code would be separated out in the tree class. The node class would be very smooth. I'll try this when I have
0
8841
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
9587
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...
0
9401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9260
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...
1
6818
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6086
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
4718
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
3328
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
2229
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.