Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
t
 
 
 
 
 
 
 
 
 
 
 
 

README.md

lua-ordered-set

Ordered set implementation in lua

Build Status

  1. It is not allowed to add duplicate into set
  2. The order of element is pre-served
  3. Adding element to head or tail is O(1) fast
  4. Adding element in middle of set is O(N) slow, discouraged
  5. Removing element from anywhere is O(1) fast
  6. Anything could be element, except nil

Example

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

About

Ordered set implementation in lua

Resources

License

Packages

No packages published
You can’t perform that action at this time.