Click here to Skip to main content
15,916,293 members
Home / Discussions / C#
   

C#

 
GeneralRe: Dictionary size issue Pin
George_George31-Oct-08 4:21
George_George31-Oct-08 4:21 
GeneralRe: Dictionary size issue Pin
Giorgi Dalakishvili31-Oct-08 4:32
mentorGiorgi Dalakishvili31-Oct-08 4:32 
GeneralRe: Dictionary size issue Pin
George_George31-Oct-08 4:45
George_George31-Oct-08 4:45 
GeneralRe: Dictionary size issue Pin
Giorgi Dalakishvili31-Oct-08 8:18
mentorGiorgi Dalakishvili31-Oct-08 8:18 
GeneralRe: Dictionary size issue Pin
led mike31-Oct-08 4:34
led mike31-Oct-08 4:34 
GeneralRe: Dictionary size issue Pin
George_George31-Oct-08 4:42
George_George31-Oct-08 4:42 
GeneralRe: Dictionary size issue Pin
led mike31-Oct-08 4:53
led mike31-Oct-08 4:53 
AnswerRe: Dictionary size issue Pin
Alan Balkany31-Oct-08 3:50
Alan Balkany31-Oct-08 3:50 
A Dictionary in C# is implemented as a hash table. There's a tradeoff between time and space here. If you use a bigger hash table, your lookups will run faster (until you exceed physical memory).

Anything you can do to reduce the amount of memory used will improve performance. For example:

1. Store all prices in a table. In your book data structure represent the price as an index into that table. (If there are no more than 65K prices, this can be a short int.) Since many different books have the same price, this will save space.

2. For the author and title, you can use Huffman coding, which will save over 50% of the space used. Huffman coding can be used to compress ASCII text so that the most common letters are represented with one or two bits, giving an average of less than one byte per letter. Since strings in .NET are Unicode, this will save you more than 50%.

3. As a simpler alternative to Huffman coding, you can use Unicode but with the UTF-8 encoding, which will be a single byte for ASCII letters, saving you 50% over UTF-16 and other encodings.

As your hash-table size gets smaller, you get more collisions (multiple keys mapped to the same slot), which slow down retrieval. The Poisson Distribution allows you to calculate the expected number of collisions, given your hash-table size and number of records. (Assuming a random hashing function.)
GeneralRe: Dictionary size issue Pin
George_George31-Oct-08 4:01
George_George31-Oct-08 4:01 
GeneralRe: Dictionary size issue Pin
Alan Balkany31-Oct-08 4:13
Alan Balkany31-Oct-08 4:13 
GeneralRe: Dictionary size issue Pin
George_George31-Oct-08 4:26
George_George31-Oct-08 4:26 
GeneralRe: Dictionary size issue Pin
Alan Balkany31-Oct-08 5:26
Alan Balkany31-Oct-08 5:26 
AnswerRe: Dictionary size issue Pin
benjymous31-Oct-08 6:01
benjymous31-Oct-08 6:01 
Questionhow i can create connection with mysql database on server using My PDA Pin
wasimsharp31-Oct-08 0:38
wasimsharp31-Oct-08 0:38 
AnswerRe: how i can create connection with mysql database on server using My PDA Pin
#realJSOP31-Oct-08 1:13
professional#realJSOP31-Oct-08 1:13 
AnswerDouble Post - Please ignore Pin
Giorgi Dalakishvili31-Oct-08 1:49
mentorGiorgi Dalakishvili31-Oct-08 1:49 
GeneralRe: Double Post - Please ignore Pin
wasimsharp31-Oct-08 1:56
wasimsharp31-Oct-08 1:56 
AnswerRe: Double Post - Please ignore Pin
Eddy Vluggen31-Oct-08 2:09
professionalEddy Vluggen31-Oct-08 2:09 
GeneralRe: Double Post - Please ignore Pin
Giorgi Dalakishvili31-Oct-08 3:21
mentorGiorgi Dalakishvili31-Oct-08 3:21 
QuestionObtaining method signature Pin
AndrusM31-Oct-08 0:21
AndrusM31-Oct-08 0:21 
QuestionMicrosoft Sync Framework Pin
Johnboyno1an30-Oct-08 23:33
Johnboyno1an30-Oct-08 23:33 
GeneralText Width Pin
kk.tvm30-Oct-08 23:17
kk.tvm30-Oct-08 23:17 
GeneralRe: Text Width Pin
Giorgi Dalakishvili30-Oct-08 23:24
mentorGiorgi Dalakishvili30-Oct-08 23:24 
GeneralRe: Text Width Pin
kk.tvm31-Oct-08 2:05
kk.tvm31-Oct-08 2:05 
GeneralRe: Text Width Pin
Giorgi Dalakishvili31-Oct-08 3:30
mentorGiorgi Dalakishvili31-Oct-08 3:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.