mirror of
https://github.com/luau-lang/rfcs.git
synced 2025-05-04 10:43:48 +01:00
Create unordered-table-remove.md
This commit is contained in:
parent
f01741502c
commit
b84301d7bf
1 changed files with 27 additions and 0 deletions
27
unordered-table-remove.md
Normal file
27
unordered-table-remove.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
# Unordered `table.remove()`
|
||||
|
||||
## Summary
|
||||
|
||||
Add an unordered remove method to the table library.
|
||||
|
||||
## Motivation
|
||||
|
||||
For arrays that are known to be unsorted, using `table.remove()` to remove indicies is unperformant, as `table.remove()` takes O(n) time to complete. This is a gross use of resources, especially if this behavior is not required by the user. Thus, it's logical to conclude that an analogous method that performs an *unordered remove* would be the clear next step.
|
||||
|
||||
## Design
|
||||
|
||||
The naming of the new method is proposed as `uremove`. However, for clarity reasons, this may not be the best name choice as `uremove` types very similar to `remove`. The implementation of the method could be as such:
|
||||
```lua
|
||||
function table.uremove(t: {any}, index: number)
|
||||
t[index], t[#t] = t[#t], nil
|
||||
end
|
||||
```
|
||||
Valid argument checking is optional.
|
||||
|
||||
## Drawbacks
|
||||
|
||||
Possibly none, apart from an extra method in the table library.
|
||||
|
||||
## Alternatives
|
||||
|
||||
Users can define the function themselves.
|
Loading…
Add table
Reference in a new issue