-
Notifications
You must be signed in to change notification settings - Fork 0
List
Dickson Law edited this page Apr 12, 2023
·
5 revisions
A data structure that stores entries sequentially and dynamically adjusts its size. Equivalent to DS Lists.
An iterator class designed to efficiently loop through the list in linear time. It stores its current position in index and current value in value.
-
hasNext(): Return whether there are more values to iterate. -
next(): Iterate to the next value. -
remove(): Remove the current value from the list. -
set(val): Set the current value in the list to the given value.
A for loop using ListIterator takes this form:
for (var i = list.iterator(); i.hasNext(); i.next()) {
/* Use i.index and i.value here */
}
-
add(...): Seeds_list_add(id, val, ...). -
clear(): Seeds_list_clear(id). -
copy(sourceList): Seeds_list_copy(id, source). -
empty(): Seeds_list_empty(id). -
findIndex(val): Seeds_list_find_index(id, val). -
findValue(pos): Seeds_list_find_value(id, pos). -
insert(pos, val): Seeds_list_insert(id, pos, val). -
read(datastr): Seeds_list_read(id, str). -
remove(pos): Seeds_list_delete(id, pos). -
replace(pos, val): Seeds_list_replace(id, pos, val). -
set(pos, val): Seeds_list_set(id, pos, val). -
shuffle(): Seeds_list_shuffle(id). -
sort([ascend], [keyer], [comparer]): Seeds_list_sort(id, ascend). Special: You can optionally specify akeyermethod taking a value and returning the value in it to compare (e.g.function(entry) { return entry.points; }for sorting a list of entries by points), and acomparermethod taking two valuesaandband returning true ifa > b(e.g.function(v1, v2) { return sqr(v1[0])+sqr(v1[1]) > sqr(v2[0])+sqr(v2[1]); }for sorting a list of 2D vectors by length). -
size(): Seeds_list_size(id). -
write(): Seeds_list_write(id).
-
get(pos): Same asfindValue(pos)
-
clone(): Return a shallow clone of the list. -
cloneDeep(): Same asclone(), but also making deep copies of everything in the list. -
copyDeep(sourceList): Same ascopy(sourceList), but with deep copies of everything in the source. -
forEach(func): Call the method or scriptfuncfor each value in the list. On each iteration, it will be passed the current value followed by the current position. -
iterator(): Return a newListIteratorset to track this list. -
mapEach(func): Set each valuevin the list tofunc(v). Iffuncthrowsundefined, the value is removed from the list. -
toArray(): Return the list's contents in array form. Note that this is a shallow conversion --- other lists nested inside will remain as lists in the returned array.