![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Skip List structure Topic Summary: Is it possible to to have more than one data element per key in a skip list? Created On: 12-Jun-2006 13:45 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() Answer: // loop through first skip list for data1 in skip1 do { print "data1=" data1 "\n" // get key - note that you must cast this to the correct type int k = (int key skip1) // use key to extract data from second skip list string data2 // if (find(skip2, k, data2)) { print "data2=" data2 "\n" } } | |
![]() |
|
Is it possible to to have more than one data element per key in a skip list?
e.g. Key Data1 Data2 0 abc f45 1 def f46 TIA! ------------------------- Heather Linsk Lead Engineer General Dynamics AIS 413-494-7095 |
|
![]() |
|
![]() |
|
No, but you can store any data structure in a skip list such as an array or another skip list.
The only trouble with storing dynamic data structures inside another dynamic data structure is that you have to be very careful about how, and in what scope, you create/delete them. Get it wrong and ... bang! I would recommend using two skip lists, one for data1 and another for data2. They both have the same key. I do this frequently. ------------------------- Tony Goodman http://www.smartdxl.com |
|
![]() |
|
![]() |
|
Thanks Tony.
Now that I am using two skip lists and I know the key of the first skip list, how do I get the related item havng the same key from the second skip list? TIA. ------------------------- Heather Linsk Lead Engineer General Dynamics AIS 413-494-7095 |
|
![]() |
|
![]() |
|
// loop through first skip list
for data1 in skip1 do { print "data1=" data1 "\n" // get key - note that you must cast this to the correct type int k = (int key skip1) // use key to extract data from second skip list string data2 // if (find(skip2, k, data2)) { print "data2=" data2 "\n" } } ------------------------- Tony Goodman http://www.smartdxl.com Edited: 12-Jun-2006 at 14:54 by Tony Goodman |
|
![]() |
|
![]() |
|
If you want you can put two data items in same list.
The trick is to use a delimited list and then parse the data item string out after retrieving the data item For a comma delimited list example: Key Data 0 abc,f45 1 def,f46 |
|
![]() |
|
![]() |
|
Ron, what a great, simple and useful idea! Do you have any good practices on parsing the data out?
------------------------- pete.kowalski(at)motorola.com |
|
![]() |
|
![]() |
|
Sorry for confusion, but are you saying that you can have 2 'Data' items for the same 'Key' this way? In your example, key 0 has 2 data items, 'abc' and 'f45'? That is, the Skip itself only has one data item, but its delimited and the user needs to un-delimit in order to use them.
If that's what you want to do, I think it would be easier to have a Skip list as the 'Data' in the original skip list. To add a new element find the internal Skip and add the Element to that. New entries in the Skip require you to create a new Skip; and when you are done you have to loop through the Skip deleting all the data Skip lists. - Louie |
|
![]() |
|
![]() |
|
After using Skip lists for awhile now ;) I often add "data" elements as delimited items and use regular expressions to parse the data back out.
For example: Skip skip1 = create() string myitem, p1, p2, p3 put(skip1, 0, "abc::123::a23s") Regexp KeyParse = regexp "(.*)::(.*)::(.*)" for myitem in skip1 do { if(KeyParse myitem) { p1 = myitem[match 1] p2 = myitem[match 2] p3 = myitem[match 3] print p1 "\t" p2 "\t" p3 "\n" } } Hope this helps! Heather ------------------------- Heather Linsk Lead Engineer General Dynamics AIS 413-494-7095 Edited: 1-Nov-2007 at 12:26 by Heather Linsk |
|
![]() |
|
![]() |
|
It looks as though your 'Data' has a fixed format with exactly 3 fields. I don't see the advantage of that over just having 3 skip parellel skip lists.
- Louie |
|
![]() |
|
![]() |
|
I guess I am not sure what the difference is either. But appearently at the time I thought there was.... :-) ------------------------- Heather Linsk Lead Engineer General Dynamics AIS 413-494-7095 |
|
![]() |
|
![]() |
|
Louie:
The advantage I see is just using one Skip list. You are not limited to have fixed format with exactly 3 fields at all. You just need to make sure you have a good enough parser to parse the data out. Heather: Thanks for the sample code. It sure helps a lot by providing direction on how to approach this. ------------------------- pete.kowalski(at)motorola.com |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Skip List structure
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.