https://github.com/basiliscos/lua-ordered-set
Ordered set implementation in lua
https://github.com/basiliscos/lua-ordered-set
Last synced: 2 months ago
JSON representation
Ordered set implementation in lua
- Host: GitHub
- URL: https://github.com/basiliscos/lua-ordered-set
- Owner: basiliscos
- License: artistic-2.0
- Created: 2016-02-21T16:51:09.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-25T20:16:16.000Z (about 9 years ago)
- Last Synced: 2025-01-18T04:31:46.239Z (4 months ago)
- Language: Lua
- Size: 14.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-ordered-set
Ordered set implementation in lua[](https://travis-ci.org/basiliscos/lua-ordered-set)
1. It is not allowed to add duplicate into set
2. The order of element is pre-served
2. Adding element to **head** or **tail** is `O(1)` fast
3. Adding element in **middle** of set is `O(N)` slow, discouraged
4. Removing element from anywhere is `O(1)` fast
5. Anything could be element, except `nil`# Example
```lua
local OrderedSet = require "OrderedSet"
local set = OrderedSet.new({"a", "b", "c"})set:insert("d")
set:insert("bb", 2) -- slow
set:remove("a")-- traverse elements in the order as they were added
for index, element in set:pairs() do
print(index .. ": " .. element)
end-- traverse elements in the reverse order
for index, element in set:pairs(true) do
print(index .. ": " .. element)
end```
Installation
============```luarocks install OrderedScope```
# License
Artistic License 2.0