Re: what is the best datatype for..



On Nov 19, 9:53 am, calvert4r...@xxxxxxxxx wrote:
I need to some sort of data type that will hold a listing of ID's and
their counts/frequency. As I do some processing I get an ID back
which I need to store and keep an accurate count for how many times
that ID is listed. For example I might get a listing of these
numbers:
1,4,6,23,6,2,54,1,6,23,2,4,1,6

I will get those numbers one at a time and need to build something
like
1,3
4,2
6,4
23,2
2,2
43,1

In above number X,Y:
X- is the number
Y- is the count of the number

I then need to sort the data on the Y (the count) column:
6,4
1,3
4,2
23,2
2,2
43,1

Can anyone suggest how best to do this. Any suggestions or help is
much appreciated!

Thanks,

Calvert

As for data types, a general rule of thumb would be that if you plan
to do some calculations with it (like addition, subtraction, etc.)
then it should be some sort of numeric type (int, double, decimal).
If you are only going to store it, then use a string. For example,
even though a phone number is all digits, you should use a string
since you don't do calculations with a phone number.

For you problem, I think your best bet would be to use a generic
dictionary. Use the ID as the key and the value as the count. Read
each value in the array, check to see if it already exists in the
dictionary. If it does, then just increment the count, otherwise, add
it to the dictionary.

Dim values() As Integer = {1,4,6,23,6,2,54,1,6,23,2,4,1,6}
Dim idCount As New Dictionary(Of String, Integer)()

For Each i As Integer In values 'Check
each value in the array
If idCount.ContainsKey(i.ToString()) Then 'If the value
already exists in the dictionary
idCount(i.ToString) += 1
'increment the count for that value

Else
'otherwise
idCount.Add(i.ToString(), 1) 'add
the value to the dictionary
End If
Next


Hope this helps

Chris
.



Relevant Pages

  • Re: Proper modularization technique
    ... will generate a string to be used by the calling routine. ... Should I set aside an array in the calling routine and have the ... the function might need to store more characters than the array ...
    (comp.lang.c)
  • Re: Data From CREATEOBJECT
    ... the first column and the "key" in the second. ... The array is public so that all of the objects can find it and the main program can find all of the objects. ... So there is no need to store it once more in the array. ... If it is a variable set of properties, then it might be better to build a long string of the property names and the respective values and store this string in a memo field. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: "Array to String Conversion" error when constructing a multi-dimensional array
    ... Don't fix bottom-posting, fix topposting..... ... I don't understand what this $increment variable has to do with ... turn the array into the string '1' somewhere. ...
    (comp.lang.php)
  • Re: Is there such a thing as dynamic arrays in classic rexx?
    ... my program but now I have a need for a dynamic array. ... String length of 0000006A000005F2 is 16 ... just store the word-numbers elsewhere. ...
    (comp.lang.rexx)
  • Re: some bit math help
    ... >> settings as a VB string. ... > I would suggest you store it as a byte array, ...
    (microsoft.public.vb.general.discussion)