Skip list

Hi, everyone.

I just found something not normal with Skip list. Here I am using Skip list to save the Absolute number of object. Before saving in skip list, everything alright, the number is same as in module. But after getting the number from Skip list, the key (absolute number) is sorted!!!!

Object o
Skip sk = createString
int num 
string str

for o in current Module do{
        if(isSelected(o)){
                str = o."Absolute Number"
                put(sk, str, str)
                print "object abs: "str "\n"
        }     
}

for str in sk do{
        str = (string key sk)
        print str "\n"
}

 

Result:

object abs: 371
object abs: 117
object abs: 397
object abs: 119
object abs: 120
object abs: 121
object abs: 122
object abs: 177
object abs: 178
object abs: 179
object abs: 180
117
119
120
121
122
177
178
179
180
371
397

What happend here? Can anyone please help? I want to get the absolute number from skip list same order as in module


Jonny Tim - Thu Jan 17 10:26:34 EST 2019

Re: Skip list auto sorting the key???
Mike.Scharnow - Thu Jan 17 10:34:42 EST 2019

yes, that's one of the features of Skip lists, in fact it is the preferred way to sort data in DXL.

Alternatives:

- use a Skip with integer as key (Skip sk = create), increase an index variable in your loop, use the index as key and str as value

- use an array

- use an Array

Re: Skip list auto sorting the key???
Jonny Tim - Thu Jan 17 11:28:38 EST 2019

Mike.Scharnow - Thu Jan 17 10:34:42 EST 2019

yes, that's one of the features of Skip lists, in fact it is the preferred way to sort data in DXL.

Alternatives:

- use a Skip with integer as key (Skip sk = create), increase an index variable in your loop, use the index as key and str as value

- use an array

- use an Array

I always thought skip list doesn't sort key. Thank you, Mike. It is really helpful.

Re: Skip list
llandale - Sat Feb 02 02:38:49 EST 2019

Scharnow is correct.
Since you are putting the identical string into both the Key and the Data, your line 15 is redundant.  And if you put different Keys and Data, then I think it a potential disaster if you extract the Key using the same variable as the Data in the loop (str in your case).  OK, not "disaster" but can extreme confusion when someone else uses your code.

Anyway, about the dangers of Skip lists.
If you are tempted to put different kinds of data as the Key or as the Data (one Key is a "Link" while another Key is an "Object"), then I say you have very seriously conceptualized the problem or solution very poorly.  Your list of streets should not include names of buildings.  If you put in an Object and then attempt to extract is as lnk=(Link key skp) you can expect a very rude error when you attempt to use the "lnk".

So now I say any particular skip list must have the consistent Key types and consistent Data type.  Through repetition of errors I've gotten over the years, I've come to two coding policies:
[1] The definition of the Skip must include the expected data types:
Skip skpStatus   // Objects and Dev Status.  KEY: 'Object'; DATA: 'string' that object's Dev Status.
[2] If the key is for strings, always use "createString()".  Otherwise always use "create()". 

[3] Do not put an "array" in a Skip.  An Array is OK.

[4] There are only 3 people in the world who can use "addr_" bla bla tricks with Skip's; I'm not one of them.
I also believe if I am tempted, then I must have conceptualized the problem wrong.
[5] For sudden expected rude errors (like DOORS completely aborting), first thing I do is find all references to "skpStatus" and insure the code is using the exact data types specified in the definition.

As for the Sorting of the Key.

[1] Integer and Real Keys are straight forward

[2] A string Key does cause problems.  Lexigraphic sorts are left to right.  If you put string "1224" into your skip, it will be retrieved BEFORE 177 in your example.
If you had some "pad" function, you could put say 6 digits into the Key; prepadded with zeros. "000124" and "001224".
[3] Other data types don't make much sense to use as a Key AND expect a reasonable sort.  I'm supposing the "sort" will be based on the address of the allocated unit or whatever.
[4] you can use an integer Sequencer to keep things sorted:
int Sequencer = 0
Skip skp = create() // KEY 'int' sequencer; DATA: 'Object' in display order

for obj in mod do

{  put(skp, Sequencer++, obj)

}

-Louie