Re: hashmap in idl [message #67440 is a reply to message #67232] |
Wed, 22 July 2009 20:30   |
b.a
Messages: 26 Registered: July 2009
|
Junior Member |
|
|
On Jul 23, 12:10 pm, David Fanning <n...@dfanning.com> wrote:
> b.a writes:
>> Sorry for being so confusing :( here is what happens to my program:
>
>> I want to have a linkedlist that has several pairs of "key"(LONG) and
>> "data"(a 2D array). each time I want to add something to the
>> linkedlist, I will specify the key(which would be an id of one of the
>> new created widgets in my program), and the data which is read from a
>> file and be kept as 2D array. number of elements added to or deleted
>> from the linkedlist is not fixed.
>
>> I used to think that if I just write for example:
>
>> key1 = 197
>> data1 = data
>> mylist = Obj_New("LINKEDLIST")
>> mylist->Add, key1, data1
>
>> it is enough and it should work. But it seems that first I have to
>> define several methods or functions - such as defining the linkedlist
>> structure, pro add-after, pro add-before, delete , ...- and then the
>> compiler would recognize what "mylist->Add, key1, data1" means and so
>> on. I mean before my main program I have to implement at least these:
>
>> PRO LINKEDLIST__DEFINE
>> PRO LINKEDLIST::ADD, item, index, Before=before, After=after
>> PRO LINKEDLIST::ADD_AFTER, item, index
>> PRO LINKEDLIST::ADD_BEFORE, item, index
>> PRO LINKEDLIST::ADD_TO_END, item
>> PRO LINKEDLIST::DELETE_NODE, index, DESTROY=destroy
>> FUNCTION LINKEDLIST::GET_NODE, index
>> FUNCTION LINKEDLIST::GET_ITEM, index, Dereference=dereference, ALL=all
>
>> here my key is actually the index, but I define it myself. I allocate
>> a number to each data. Is it true?
>
> No, it is not true. In fact, it is so far from being true
> it isn't even wrong. It's...I don't know. Nonsense, probably. :-)
>
> But, clearly, you must have some reason for believing this.
> What I have been trying to understand, so I can help you,
> is what this reason is. Do you have some *evidence* you
> would like to present that supports your idea?
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")- Hide quoted text -
>
> - Show quoted text -
Hi David,
I didn't say I believe this, I am totally in doupt!!! But that was my
understanding of linkedlist from what I searched on the web. The very
first problem that I have is that I do not know how to define a
linkedlist and add elements to it.
For other data structure, for example arrays, I can write a code which
means create a 2D array. Add (x,y) to it or delete[m,n] from it, but I
dont know how to write "create a linkedlist" and then add this to the
linked list:
key1 data1
key2 data2
key3 data3
.
.
.
and then delete keyN dataN, etc.
for example in this code:
pro test
mylist = Obj_New("LINKEDLIST", 5)
mylist->Add, 10
mylist->Add, 7, 1, /Before
mylist->Add, 12
print, mylist->Get_Item(/All, /Deref)
mylist->Replace_Item, 1, 'Bob'
mylist->Help
mylist->Delete
mylist->Help, /Print
end
when I just copy and paste it and compile it, it complains:
% Attempt to call undefined procedure/function: 'LINKEDLIST__DEFINE'.
% Execution halted at: TEST , ....
thats why I thought I have to write other programs in addition to
above to define the structure, Add, get-item and so on.
Cheers
|
|
|