code/__HELPERS/lists.dm
COMPARE_KEY | Passed into BINARY_INSERT to compare keys |
---|---|
COMPARE_VALUE | Passed into BINARY_INSERT to compare values |
BINARY_INSERT_TG | Binary search sorted insert from TG INPUT: Object to be inserted LIST: List to insert object into TYPECONT: The typepath of the contents of the list COMPARE: The object to compare against, usualy the same as INPUT COMPARISON: The variable on the objects to compare COMPTYPE: How should the values be compared? Either COMPARE_KEY or COMPARE_VALUE. |
LIST_VALUE_WRAP_LISTS | If value is a list, wrap it in a list so it can be used with list add/remove operations |
UNTYPED_LIST_ADD | Add an untyped item to a list, taking care to handle list items by wrapping them in a list to remove the footgun |
/proc/pickweight | Picks an element based on its weight. L - The input list |
/proc/pick_multiple_unique | Picks multiple unique elements from the suplied list. If the given list has a length less than the amount given then it will return a list with an equal amount |
LAZYINITLIST | Initialize the lazylist |
UNSETEMPTY | If the provided list is empty, set it to null |
ASSOC_UNSETEMPTY | If the provided key -> list is empty, remove it from the list |
LAZYLISTDUPLICATE | Like LAZYCOPY - copies an input list if the list has entries, If it doesn't the assigned list is nulled |
LAZYREMOVE | Remove an item from the list, set the list to null if empty |
LAZYADD | Add an item to the list, if the list is null it will initialize it |
LAZYOR | Add an item to the list if not already present, if the list is null it will initialize it |
LAZYDISTINCTADD | Adds I to L, initializing L if necessary, if I is not already in L |
LAZYACCESS | returns L[I] if L exists and I is a valid index of L, runtimes if L is not a list |
LAZYLEN | Returns the length of L |
LAZYNULL | Sets a list to null |
LAZYCLEARLIST | Removes all elements from the list |
LAZYCOPY | Use LAZYLISTDUPLICATE instead if you want it to null with no entries |
LAZYSET | Sets the item K to the value V, if the list is null it will initialize it |
LAZYSETLEN | Sets the length of a lazylist |
LAZYADDASSOC | Adds to the item K the value V, if the list is null it will initialize it |
LAZYADDASSOCLIST | This is used to add onto lazy assoc list when the value you're adding is a /list/. This one has extra safety over lazyaddassoc because the value could be null (and thus cant be used to += objects) |
LAZYREMOVEASSOC | Removes the value V from the item K, if the item K is empty will remove it from the list, if the list is empty will set the list to null |
LAZYACCESSASSOC | Accesses an associative list, returns null if nothing is found |
QDEL_LAZYLIST | Qdel every item in the list before setting the list to null |
LAZYIN | If the lazy list is currently initialized find item I in list L |
ISINDEXSAFE | Returns whether a numerical index is within a given list's bounds. Faster than isnull(LAZYACCESS(L, I)). |
LAZYORASSOCLIST | Performs an insertion on the given lazy list with the given key and value. If the value already exists, a new one will not be made. |
/proc/make_associative | A proc for turning a list into an associative list. |
/proc/compare_list | compare two lists, returns TRUE if they are the same |
/proc/avoid_assoc_duplicate_keys | takes an input_key, as text, and the list of keys already used, outputting a replacement key in the format of "[input_key] ([number_of_duplicates])" if it finds a duplicate use this for lists of things that might have the same name, like mobs or objects, that you plan on giving to a player as input |
/proc/assoc_to_keys | Turns an associative list into a flat list of keys |
/proc/fill_with_ones | Given a list, return a copy where values without defined weights are given weight 1. For example, fill_with_ones(list(A, B=2, C)) = list(A=1, B=2, C=1) Useful for weighted random choices (loot tables, syllables in languages, etc.) |
/proc/pick_weight_recursive | Like pick_weight, but allowing for nested lists. |
/proc/lists_equal_unordered | Checks to make sure that the lists have the exact same contents, ignores the order of the contents. |
Define Details
ASSOC_UNSETEMPTY
If the provided key -> list is empty, remove it from the list
BINARY_INSERT_TG
Binary search sorted insert from TG INPUT: Object to be inserted LIST: List to insert object into TYPECONT: The typepath of the contents of the list COMPARE: The object to compare against, usualy the same as INPUT COMPARISON: The variable on the objects to compare COMPTYPE: How should the values be compared? Either COMPARE_KEY or COMPARE_VALUE.
COMPARE_KEY
Passed into BINARY_INSERT to compare keys
COMPARE_VALUE
Passed into BINARY_INSERT to compare values
ISINDEXSAFE
Returns whether a numerical index is within a given list's bounds. Faster than isnull(LAZYACCESS(L, I)).
LAZYACCESS
returns L[I] if L exists and I is a valid index of L, runtimes if L is not a list
LAZYACCESSASSOC
Accesses an associative list, returns null if nothing is found
LAZYADD
Add an item to the list, if the list is null it will initialize it
LAZYADDASSOC
Adds to the item K the value V, if the list is null it will initialize it
LAZYADDASSOCLIST
This is used to add onto lazy assoc list when the value you're adding is a /list/. This one has extra safety over lazyaddassoc because the value could be null (and thus cant be used to += objects)
LAZYCLEARLIST
Removes all elements from the list
LAZYCOPY
Use LAZYLISTDUPLICATE instead if you want it to null with no entries
LAZYDISTINCTADD
Adds I to L, initializing L if necessary, if I is not already in L
LAZYIN
If the lazy list is currently initialized find item I in list L
LAZYINITLIST
Initialize the lazylist
LAZYLEN
Returns the length of L
LAZYLISTDUPLICATE
Like LAZYCOPY - copies an input list if the list has entries, If it doesn't the assigned list is nulled
LAZYNULL
Sets a list to null
LAZYOR
Add an item to the list if not already present, if the list is null it will initialize it
LAZYORASSOCLIST
Performs an insertion on the given lazy list with the given key and value. If the value already exists, a new one will not be made.
LAZYREMOVE
Remove an item from the list, set the list to null if empty
LAZYREMOVEASSOC
Removes the value V from the item K, if the item K is empty will remove it from the list, if the list is empty will set the list to null
LAZYSET
Sets the item K to the value V, if the list is null it will initialize it
LAZYSETLEN
Sets the length of a lazylist
LIST_VALUE_WRAP_LISTS
If value is a list, wrap it in a list so it can be used with list add/remove operations
QDEL_LAZYLIST
Qdel every item in the list before setting the list to null
UNSETEMPTY
If the provided list is empty, set it to null
UNTYPED_LIST_ADD
Add an untyped item to a list, taking care to handle list items by wrapping them in a list to remove the footgun