User talk:ANSI Soderstrom/Simple LSL Array (Associative)

From Second Life Wiki
Jump to navigation Jump to search


Thoughts

  1. Why are you supporting multiple values for a key? It looks like you only return the last one with GET. PUT updates all of them which sorta makes having them pointless.
  2. Where is the REMOVE function?
  3. This is not what I think of when i think of "array" nor a simple one at that, what you have here is an ""Wikipedia logo"associative array".

-- Strife (talk|contribs) 06:24, 22 April 2010 (UTC)

A quick implementation

It's possible that it's not the best way to implement the loop condition. But it's clever. I've also added support for setting and removing multiple keys at a time. This is for convenience and there is little to no performance gain from doing this vs individual calls. I've checked the logic, it should work, I haven't tested it though. -- Strife (talk|contribs) 07:14, 22 April 2010 (UTC)

<lsl>list GET(list ARRAY, list KEY) {

   if(llGetListLength(KEY) == 1) {
       integer position = llListFindList(ARRAY, KEY) + 1;
       if(position) {
           return llList2List(ARRAY, position, position);
       }
   }
   return [];

}

list PUT(list ARRAY, list KEY, list VALUE){

   integer len = -llGetListLength(KEY);
   if(len == -llGetListLength(VALUE) && len) {
       integer position;
       do {
           list temp = [];
           list Key = llList2List(KEY, len, len);
           while((position & 1) == !(position = llListFindList(ARRAY, Key) + 1)) {
               temp = temp + llList2List(ARRAY, 0, position);
               ARRAY = llDeleteSubList(ARRAY, 0, position);
           }
           if(position) {
               ARRAY = temp + llListReplaceList(ARRAY, llList2List(VALUE, len, len), position, position);
           } else {
               ARRAY = temp + ARRAY + Key + llList2List(VALUE, len, len);
           }
       } while( ++len );
   }
   return ARRAY;

}

list REMOVE(list ARRAY, list KEY){

   integer len = -llGetListLength(KEY);
   if(len) {
       do {
           list temp = [];
           integer position;
           list Key = llList2List(KEY, len, len);
           while((position & 1) == !(position = llListFindList(ARRAY, Key) + 1)) {
               temp += llList2List(ARRAY, 0, position);
               ARRAY = llDeleteSubList(ARRAY, 0, position);
           }
           if(position) {
               ARRAY = temp + llDeleteSubList(ARRAY, position - 1, position);
           } else {
               ARRAY = temp + ARRAY;
           }
       } while( ++len );
   }
   return ARRAY;

} </lsl> -- Strife (talk|contribs) 07:14, 22 April 2010 (UTC)


Answers

Hi Strife. I expected you ;)

Question
Why are you supporting multiple values for a key? It looks like you only return the last one with GET. PUT updates all of them which sorta makes having them pointless.
Answer
I dont support multiple Values for a Key. I allow only one Value (per Type) per Key. But its the posibillity that a KEY can have the same spelling like a VALUE
e.g. TEST3 = KEY1 / FAIL1 = TEST2 / FAIL2 = TEST1 / TEST2 = TEST1 / KEY1 = TEST2
^^^try to get the right values with your GET-Method and u will see what i mean ;)
Question
Where is the REMOVE function?
Answer
Uh Oh. Sorry. Simple LSL Array (Associative) updated !
Question
This is not what I think of when i think of "array" nor a simple one at that, what you have here is an ""Wikipedia logo"associative array".
Answer
U win !
It would be nice..
...if u can comment your code, then we can all reproduce what those lines exactly do.
...if u can post some examples with your functions.

ANSI Soderstrom 06:20, 23 April 2010 (UTC)

  1. It doesn't work? It should be handling the Key-Value confusion (though I was really tired when I wrote it). I'll see if I can get it working properly tomorrow.
  2. Good job on the ERASE function.
  3. wasn't looking to win. :-/
  4. hmmmm....
    • I'll work on commenting it (I find comments distracting when I have internalized the code).
    • Do you mind if I just retool your examples?

-- Strife (talk|contribs) 05:28, 25 April 2010 (UTC)

4
Uh Oh. No, please get me wrong. Often i would talk with other sentences but my Translator isn´t really a advantage. So i have to write other words (and sentences) as i want. I mind nothing... Iam happy for all comments on my different wiki-sites and i don´t want to be rude. Iam sorry about my angular-ism :) For 3 years ago i can´t speak any whole english-spelling sentence (at this point a BIG TYVM to LL for this 'low-cost interactive and very much fun-making language learning system' called SecondLife or 'LCIVMFMLLS'), please give me 3 years again and we can joking about our mothers without any trouble or double thinking.... ;)
3
Maybe. But u are right. So i have moved this site to prevent further confusings. Head up! It´s all well ;)
2
This is the first time in my whole live that i hear this sentence. What it means ? O.o U are kidding me, not ?
1
No, it doesn´t work. And exact THIS behavior and confusing was the reason for writing the whole "Associative Array". :)

ANSI Soderstrom 14:24, 25 April 2010 (UTC)