Skip to content

basiliscos/lua-ordered-set

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

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

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

Stars

Watchers

Forks

Packages

No packages published