code/__HELPERS/_lists.dm 
| 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 |
| UNTYPED_LIST_REMOVE | Remove an untyped item to a list, taking care to handle list items by wrapping them in a list to remove the footgun |
| 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 |
| LAZYFIND | Returns the key of the submitted item in the list |
| LAZYACCESS | returns L[I] if L exists and I is a valid index of L, runtimes if L is not a list |
| 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 |
| LAZYLEN | Returns the length of the list |
| LAZYNULL | Sets a list to null |
| 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 |
| LAZYCOPY | Use LAZYLISTDUPLICATE instead if you want it to null with no entries |
| LAZYCLEARLIST | Consider LAZYNULL instead |
| SANITIZE_LIST | Returns the list if it's actually a valid list, otherwise 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. |
| LAZYINSERT | Calls Insert on the lazy list if it exists, otherwise initializes it with the value |
| LISTASSERTLEN | Ensures the length of a list is at least I, prefilling it with V if needed. if V is a proc call, it is repeated for each new index so that list() can just make a new list for each item. |
| LAZYIN | If the lazy list is currently initialized find item I in list L |
| LAZYREINITLIST | Clears a list and then re-initializes it |
| ISINDEXSAFE | Returns whether a numerical index is within a given list's bounds. Faster than isnull(LAZYACCESS(L, I)). |
| COMPARE_KEY | Passed into BINARY_INSERT to compare keys |
| COMPARE_VALUE | Passed into BINARY_INSERT to compare values |
| BINARY_INSERT | 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. |
| BINARY_INSERT_PROC_COMPARE | Custom binary search sorted insert utilising comparison procs instead of vars. 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 plaintext name of a proc on INPUT that takes a single argument to accept a single element from LIST and returns a positive, negative or zero number to perform a comparison. COMPTYPE: How should the values be compared? Either COMPARE_KEY or COMPARE_VALUE. |
| BINARY_INSERT_DEFINE | Even more custom binary search sorted insert, using defines instead of vars INPUT: Item to be inserted LIST: List to insert INPUT into TYPECONT: A define setting the var to the typepath of the contents of the list COMPARE: The item to compare against, usualy the same as INPUT COMPARISON: A define that takes an item to compare as input, and returns their comparable value COMPTYPE: How should the list be compared? Either COMPARE_KEY or COMPARE_VALUE. |
| /proc/english_list | Returns a list in plain english as a string |
| /proc/russian_list | Returns a list in plain russian as a string |
| /proc/listgetindex | Returns list element or null. Should prevent "index out of bounds" error. |
| /proc/safepick | Return either pick(list) or null if list is not of type /list or is empty |
| /proc/peek | Returns the top (last) element from the list, does not remove it from the list. Stack functionality. |
| /proc/isemptylist | Checks if the list is empty |
| /proc/is_type_in_list | Checks if an atom is of a type present in the given list |
| /proc/is_type_in_typecache | Checks if an atom's type is present in a typecache list |
| /proc/typecache_filter_list | Returns a new list with only atoms that are in the provided typecache |
| /proc/typecache_filter_list_reverse | Returns a new list with atoms that are not in the provided typecache |
| /proc/typecache_filter_multi_list_exclusion | Filters atoms using both inclusion and exclusion typecaches |
| /proc/typecacheof | Like typesof() or subtypesof(), but returns a typecache instead of a list |
| /proc/subtypesof | Returns a list containing all subtypes of the given path, but not the given path itself. |
| /proc/list_clear_nulls | Removes any null entries from the list Returns TRUE if the list had nulls, FALSE otherwise |
| /proc/list_clear_empty_weakrefs | Removes any empty weakrefs from the list Returns TRUE if the list had empty refs, FALSE otherwise |
| /proc/difflist | Returns list containing all the entries from first list that are not present in second. If skiprep = TRUE, repeated elements are treated as one. If either of arguments is not a list, returns null |
| /proc/pickweight | Picks a random element from a list based on a weighting system. All keys with zero or non integer weight will be considered as one For example, given the following list: A = 5, B = 3, C = 1, D = 0 A would have a 50% chance of being picked, B would have a 30% chance of being picked, C would have a 10% chance of being picked, and D would have a 10% chance of being picked. This proc not modify input list |
| /proc/pick_weight_classic | Picks a random element from a list based on a weighting system. All keys with zero or non integer weight will be considered as zero For example, given the following list: A = 6, B = 3, C = 1, D = 0 A would have a 60% chance of being picked, B would have a 30% chance of being picked, C would have a 10% chance of being picked, and D would have a 0% chance of being picked. This proc not modify input list |
| /proc/pick_n_take | Pick a random element from the list and remove it from the list. |
| /proc/pick_weight_recursive | Like pick_weight, but allowing for nested lists. |
| /proc/pick_weight_n_take | Picks a random element by weight from the list and removes it from the 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 |
| /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/pop | Returns the top (last) element from the list, does not remove it from the list. Stack functionality. |
| /proc/popleft | Returns the first element from the list and removes it. Queue functionality. |
| /proc/shuffle | Returns a new list with the elements in random order |
| /proc/bitfield_to_list | Converts a bitfield to a list of numbers (or words if a wordlist is provided) |
| KEYBYINDEX | Returns the key based on the index |
| /proc/count_by_type | Counts the number of items of a specified type in a list |
| /proc/deep_copy_list | Recursively copies a list and all lists contained within it Does not copy any other reference types |
| DEFAULTPICK | Picks from the list, with some safeties, and returns the "default" arg if it fails |
| /proc/shuffle_inplace | Shuffles a list in place and returns the same list |
| /proc/unique_list | Returns a new list with no duplicate entries |
| /proc/unique_list_in_place | Removes duplicate entries from a list in place, preserving associated values |
| /proc/move_element | Moves a single element from one position to another within a list, preserving associations |
| /proc/move_range | Moves a range of elements from one position to another within a list, preserving associations |
| /proc/swap_range | Swaps two ranges of elements within a list, preserving order of overwritten elements Note: If ranges overlap, only the destination order will be fully preserved |
| /proc/counterlist_scale | Scales all values in a counter list by a given scalar factor |
| /proc/counterlist_sum | Calculates the sum of all values in a counter list |
| /proc/counterlist_normalise | Normalizes a counter list by dividing each value by the total sum |
| /proc/counterlist_combine | Combines two counter lists by adding values for matching keys |
| /proc/make_associative | A proc for turning a list into an associative list. |
| /proc/list_clear_duplicates | Removes all occurrences of a specified element from a list |
| /proc/sort_list | sort any value in a list |
| /proc/sort_names | uses sort_list() but uses the var's name specifically |
| /proc/expand_weights | Takes a weighted list and expands it into raw entries This eats more memory, but saves time when actually picking from it |
| /proc/greatest_common_factor | Takes a list of numbers and returns the highest value that cleanly divides them all Note: this implementation is expensive for large numbers, intended for small lists |
| /proc/compare_list | Compare two lists, returns TRUE if they are the same |
| /proc/assert_sorted | Verifies that a list is sorted according to the given comparator function Throws a runtime error if the list is not sorted |
| /proc/assoc_to_keys | Converts an associative list into a flat list of keys |
| /proc/reverse_range | Reverses the order of elements in a list within the specified range Replaces reverseList ~Carnie |
| /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/lists_equal_unordered | Checks if two lists contain the same elements, ignoring order |
| /proc/print_single_line | Converts a list to a string representation in "list(key => value, ...)" format |
| /proc/get_list_count | Counts the number of nested lists within a list, up to a maximum count |
Define Details
ASSOC_UNSETEMPTY 
If the provided key -> list is empty, remove it from the list
BINARY_INSERT 
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.
BINARY_INSERT_DEFINE 
Even more custom binary search sorted insert, using defines instead of vars INPUT: Item to be inserted LIST: List to insert INPUT into TYPECONT: A define setting the var to the typepath of the contents of the list COMPARE: The item to compare against, usualy the same as INPUT COMPARISON: A define that takes an item to compare as input, and returns their comparable value COMPTYPE: How should the list be compared? Either COMPARE_KEY or COMPARE_VALUE.
BINARY_INSERT_PROC_COMPARE 
Custom binary search sorted insert utilising comparison procs instead of vars. 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 plaintext name of a proc on INPUT that takes a single argument to accept a single element from LIST and returns a positive, negative or zero number to perform a comparison. 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
DEFAULTPICK 
Picks from the list, with some safeties, and returns the "default" arg if it fails
ISINDEXSAFE 
Returns whether a numerical index is within a given list's bounds. Faster than isnull(LAZYACCESS(L, I)).
KEYBYINDEX 
Returns the key based on the index
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 
Consider LAZYNULL instead
LAZYCOPY 
Use LAZYLISTDUPLICATE instead if you want it to null with no entries
LAZYFIND 
Returns the key of the submitted item in the list
LAZYIN 
If the lazy list is currently initialized find item I in list L
LAZYINITLIST 
Initialize the lazylist
LAZYINSERT 
Calls Insert on the lazy list if it exists, otherwise initializes it with the value
LAZYLEN 
Returns the length of the list
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.
LAZYREINITLIST 
Clears a list and then re-initializes it
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
LISTASSERTLEN 
Ensures the length of a list is at least I, prefilling it with V if needed. if V is a proc call, it is repeated for each new index so that list() can just make a new list for each item.
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
SANITIZE_LIST 
Returns the list if it's actually a valid list, otherwise will initialize it
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
UNTYPED_LIST_REMOVE 
Remove an untyped item to a list, taking care to handle list items by wrapping them in a list to remove the footgun