Skip to content

Commit

Permalink
add next, minimum, maximum
Browse files Browse the repository at this point in the history
  • Loading branch information
broma0 committed Apr 12, 2024
1 parent 82f1abe commit 3adee32
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/todo.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Now

- bitmap.create from raw string

# Eventually

- Allow specifying int type to use for raw bitmaps
11 changes: 10 additions & 1 deletion lib/santoku/bitmap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ local function raw_matrix (bs, n, s, e)
return bm.raw(b0, #bs * step)
end

local function next (b, i)
for j = i + 1, bm.maximum(b) do
if bm.get(b, j) then
return j
end
end
end

return merge({
raw_matrix = raw_matrix
raw_matrix = raw_matrix,
next = next
}, bm)
18 changes: 18 additions & 0 deletions lib/santoku/bitmap/capi.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ static int cardinality (lua_State *L)
return 1;
}

static int minimum (lua_State *L)
{
lua_settop(L, 1);
roaring_bitmap_t *bm = peek(L, 1);
lua_pushinteger(L, roaring_bitmap_minimum(bm) + 1);
return 1;
}

static int maximum (lua_State *L)
{
lua_settop(L, 1);
roaring_bitmap_t *bm = peek(L, 1);
lua_pushinteger(L, roaring_bitmap_maximum(bm) + 1);
return 1;
}

static int clear (lua_State *L)
{
lua_settop(L, 1);
Expand Down Expand Up @@ -237,6 +253,8 @@ static luaL_Reg fns[] =
{ "get", get },
{ "unset", unset },
{ "cardinality", cardinality },
{ "minimum", minimum },
{ "maximum", maximum },
{ "clear", clear },
{ "raw", raw },
{ "tostring", tostring },
Expand Down
2 changes: 1 addition & 1 deletion make.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local env = {

name = "santoku-bitmap",
version = "0.0.6-1",
version = "0.0.7-1",
variable_prefix = "TK_BITMAP",
public = true,

Expand Down

0 comments on commit 3adee32

Please sign in to comment.