25 lines
677 B
Lua
25 lines
677 B
Lua
|
--Partial sequence s:S->N, S <= N, N = { 1, 2, 3, ... }
|
||
|
--Consists of:
|
||
|
--A sequence stored as a (sparse) array
|
||
|
--["cmin"], a key whose value is the smallest element outside the support of the sequence
|
||
|
local sequence = {}
|
||
|
sequence.__index = sequence
|
||
|
function sequence.new( name )
|
||
|
return setmetatable( { cmin = 1, name = name }, sequence )
|
||
|
end
|
||
|
|
||
|
function sequence:insert( x, y )
|
||
|
if self.cmin == x then
|
||
|
repeat self.cmin = self.cmin + 1 until not self[self.cmin]
|
||
|
end
|
||
|
self[x] = y
|
||
|
--debug:
|
||
|
--print( "First unclaimed element:", self.name, self.cmin )
|
||
|
end
|
||
|
|
||
|
--Maybe leave this for later, we'll inline it for now.
|
||
|
function sequence:complement()
|
||
|
|
||
|
end
|
||
|
|
||
|
return sequence
|