GML Can Someone Explain ds_lists To Me?

K

koopy eacret

Guest
Can Someone Explain ds_lists To Me?
I Just Dont Understand Them
 

jo-thijs

Member
Can Someone Explain ds_lists To Me?
I Just Dont Understand Them
Code:
newList = ds_list_create();

ds_list_add(newList, 5); // The list is now {5}
ds_list_add(newList, "test"); // The lis is now {5, "test"}

value1 = ds_list_find_value(newList, 1); // value1 is now "test"
value2 = ds_list_find_value(newList, 0); // value2 is now 5

ds_list_delete(newList, 0); // The list is now {"test"}

ds_list_insert(newList, 0, 9); // The list is now {9, "test"}

ds_list_destroy(newList); // Now the memory used up by the list is freed
 
#### Viewer Discretion Advised, The Following BroadCast May Or May Not Be Suitable For Actually Understanding DS Lists ####

Let me tell you a story of amazement, a ds_list is a truly wondrous thing. A magical bag of holding. A cornucopia of joy and data.

Ye may call one forth by simply invoking the spirits of ds_lists:

magnificent_list = ds_list_create()

The owner of this delightful bag of goodness may place things into it as they wish...strings of gold, numbers of silver, and booleans of bronze.

ds_list_add(magnificent_list, "Doubloons")

A thing added to such a powerful bag is given a number by which to live by.

The first thing offered to the bag is gifted the glorious number 0, and if followed by a second thing, that second thing shall be forever known as the the thing that was numbered 1. (Until it isn't)

And if, perchance, a third thing be added, it be granted the label of 2.

This continues as long as things are added to the bag.

The owner of the Bag 'O' DS List may, at will, take a peek at things in the bag my merely whispering its labelled number.

If ye be placing a string that says "Glory to GameMaker" as the first thing in the bag, ye may call it forth by saying, O Mighty Bag, show the the fairest string of them all, that string belonging to the first thing I put in the bag, that by which they call item 0.

show_debug_message( magnificent_list[| 0] )

...will faithfully print "Glory to GameMaker"...

And Lo, the bag shall surely reply, here be ye string, it be "Glory to GameMaker".

And if ye wish, yonder bag will tell you how many items you have in it, even if ye haven't been taking note of how many things ye be puttin' in it....

Just say unto the bag, the magic words:

"ds_list_size(magnificent_list)"

...and as surely as the sun will rise, the bag will tell you how many items are in it, by means as yet unknown to commonfolks.

So forevermore, the faithful DS 'O' List may be considered an arcane bag of mysterious holding, with which ye can put things in and look at them as ye wish, as well as taking the things that were put before an' removing them.

Just remember, don't get it wet...don't feed it after midnight...and surely don't forget to dispose of it when thou need for it has ended, or a mighty memory leak shall be given unto thee....

ds_list_destroy(magnificent_list)

And there ends me cautionary tale. A DS List treated well will be a lifetime friend...but treated poorly...will be the undoing of ye merry game.
EDIT : Added Spoiler Tags Because Wall Of Text
 
Last edited:

jo-thijs

Member
Yeah.
Just insert a more between two other nodes.
That's assuming you already have the nodes address, having previously iterated or something.
Under that assumption, accessing a value from the list is also an O(1) operation.
 

NicoFIDI

Member
it depends, add a value to the end or the begining it's a O(1) on the linked lists i code in C.
insert in a arbitrary place it's O(n) in array implementation and O(index) in the linked list.
i know O(index) it's not an order, but i use it to show that the linked list it's 99% of the times faster
because you dont need to resize, make new array or nothing like that.

True reality: both are O(n)

Edit: also, in linked list you can use an iterator to make the insertion in O(1) while you process something else.
Edit2: Sorry for the host of the thread if this is too tecnical, try reading data structures in general, how it works should be "black boxed" (hidden) for you :)
 
Last edited:
B

Blaze

Guest
#### Viewer Discretion Advised, The Following BroadCast May Or May Not Be Suitable For Actually Understanding DS Lists ####

Let me tell you a story of amazement, a ds_list is a truly wondrous thing. A magical bag of holding. A cornucopia of joy and data.

Ye may call one forth by simply invoking the spirits of ds_lists:

magnificent_list = ds_list_create()

The owner of this delightful bag of goodness may place things into it as they wish...strings of gold, numbers of silver, and booleans of bronze.

ds_list_add(magnificent_list, "Doubloons")

A thing added to such a powerful bag is given a number by which to live by.

The first thing offered to the bag is gifted the glorious number 0, and if followed by a second thing, that second thing shall be forever known as the the thing that was numbered 1. (Until it isn't)

And if, perchance, a third thing be added, it be granted the label of 2.

This continues as long as things are added to the bag.

The owner of the Bag 'O' DS List may, at will, take a peek at things in the bag my merely whispering its labelled number.

If ye be placing a string that says "Glory to GameMaker" as the first thing in the bag, ye may call it forth by saying, O Mighty Bag, show the the fairest string of them all, that string belonging to the first thing I put in the bag, that by which they call item 0.

show_debug_message( magnificent_list[| 0] )

...will faithfully print "Glory to GameMaker"...

And Lo, the bag shall surely reply, here be ye string, it be "Glory to GameMaker".

And if ye wish, yonder bag will tell you how many items you have in it, even if ye haven't been taking note of how many things ye be puttin' in it....

Just say unto the bag, the magic words:

"ds_list_size(magnificent_list)"

...and as surely as the sun will rise, the bag will tell you how many items are in it, by means as yet unknown to commonfolks.

So forevermore, the faithful DS 'O' List may be considered an arcane bag of mysterious holding, with which ye can put things in and look at them as ye wish, as well as taking the things that were put before an' removing them.

Just remember, don't get it wet...don't feed it after midnight...and surely don't forget to dispose of it when thou need for it has ended, or a mighty memory leak shall be given unto thee....

ds_list_destroy(magnificent_list)

And there ends me cautionary tale. A DS List treated well will be a lifetime friend...but treated poorly...will be the undoing of ye merry game.
Haha that was the best!
 
Top