Forest Logo
search
package_2

simplesuite

By @gigahd

Roblox

Mirrored

SimpleSuite

A Collection of simple Data Structures that I use in my games.

Includes

  • SimpleStack
  • SimpleQueue (O(1) amortized enqueue/dequeue)
  • SimpleList
  • SimplePriorityQueue (binary heap)

Every structure shares a consistent surface: Size, IsEmpty, Clear, Has, Remove (removes the first element equal to a value, returning a boolean), RemoveWhere (removes the first element satisfying a predicate, returning the removed element or nil), and Iterator, plus its own operations. Each constructor takes an optional capacity to pre-reserve the backing array. (On List, removal by index is RemoveAt; Remove is by value, like the other structures.)

RemoveWhere is the one to reach for when you only know a sub-value:

local players = SimpleSuite.List()
players:Append({ id = 1, name = "Ana" })
players:Append({ id = 2, name = "Bo" })

local removed = players:RemoveWhere(function(p)
    return p.id == 2
end)
print(removed.name) --> Bo

On PriorityQueue, RemoveWhere removes the highest-priority match (the same element Find would return).

Get it on Wally

Usage

Note: As of 0.3.0 the structures are metatable-based and use method (colon) call syntax, e.g. stack:Push(x). This is a breaking change from 0.2.x, which used dot calls.

local SimpleSuite = require(path.to.SimpleSuite)

-- Stack (LIFO)
local stack = SimpleSuite.Stack()
stack:Push(1)
stack:Push(2)
print(stack:Pop()) --> 2

-- Queue (FIFO)
local queue = SimpleSuite.Queue()
queue:Enqueue("a")
queue:Enqueue("b")
print(queue:Dequeue()) --> a

-- List
local list = SimpleSuite.List()
list:Append(10)
list:Prepend(5)
print(list:Get(1)) --> 5

-- PriorityQueue (comparator: return true when `a` should leave before `b`)
local pq = SimpleSuite.PriorityQueue(function(a, b)
    return a < b -- min-heap
end)
pq:Enqueue(3)
pq:Enqueue(1)
print(pq:Dequeue()) --> 1

-- Iterate any structure
for index, value in stack:Iterator() do
    print(index, value)
end

-- Pre-reserve capacity for a known workload
local big = SimpleSuite.List(10_000)

Package Details

Install command (Click to copy)


Version

0.3.1

License

MIT

check_circle

Safe for commercial use

Automated license review — not legal advice.