K
koopy eacret
Guest
Can Someone Explain ds_lists To Me?
I Just Dont Understand Them
I Just Dont Understand Them
Can Someone Explain ds_lists To Me?
I Just Dont Understand Them
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
That's not true though.That's what a "ds list" is:
Lots of cool info in there: https://en.wikipedia.org/wiki/Linked_list
Now that's interesting. They do look/behave like linked lists though.That's not true though.
Last time I heard, lists were implemented as resizing arrays in GameMaker.
In essence this can change over versions of GameMaker and targets for which you are developping.
EDIT:
See this for reference:
http://gmc.yoyogames.com/index.php?showtopic=646789&hl=+linked++list
not quite: random access is O[1] not O[N] like a linked list would be.They do look/behave like linked lists though.
Insert is O(1) in a linked list?not quite: random access is O[1] not O[N] like a linked list would be.
insert and delete are also O[N], not O[1] like in a linked list.
GM should have both if you ask me...
Yeah.Insert is O(1) in a linked list?
Under that assumption, accessing a value from the list is also an O(1) operation.Yeah.
Just insert a more between two other nodes.
That's assuming you already have the nodes address, having previously iterated or something.
Haha that was the best!#### 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.