summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-21 21:22:17 +0800
committerruki <[email protected]>2022-05-21 21:22:17 +0800
commitdbc34e84e8cbdaa3b2482e825b44aec311eafc1b (patch)
treedf9a56d68efc15bd8bc25801b5abe2a6b7d770c9
parent56defbb27a476695f6527ecd633140221a7b7148 (diff)
add clear for bloom filter
-rw-r--r--core/src/xmake/bloom_filter/bloom_filter_clear.c54
-rw-r--r--core/src/xmake/bloom_filter/bloom_filter_data.c55
-rw-r--r--core/src/xmake/bloom_filter/bloom_filter_data_set.c66
-rw-r--r--core/src/xmake/bloom_filter/bloom_filter_size.c55
-rw-r--r--core/src/xmake/engine.c14
-rw-r--r--core/src/xmake/makefile6
-rw-r--r--xmake/core/base/bytes.lua7
7 files changed, 250 insertions, 7 deletions
diff --git a/core/src/xmake/bloom_filter/bloom_filter_clear.c b/core/src/xmake/bloom_filter/bloom_filter_clear.c
new file mode 100644
index 000000000..2a9da2dca
--- /dev/null
+++ b/core/src/xmake/bloom_filter/bloom_filter_clear.c
@@ -0,0 +1,54 @@
+/*!A cross-platform build utility based on Lua
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file bloom_filter_clear.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "bloom_filter_clear"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_bloom_filter_clear(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // is pointer?
+ if (!xm_lua_ispointer(lua, 1))
+ return 0;
+
+ // get the bloom filter
+ tb_bloom_filter_ref_t filter = (tb_bloom_filter_ref_t)xm_lua_topointer(lua, 1);
+ tb_check_return_val(filter, 0);
+
+ // clear filter
+ tb_bloom_filter_clear(filter);
+ lua_pushboolean(lua, tb_true);
+ return 1;
+}
+
diff --git a/core/src/xmake/bloom_filter/bloom_filter_data.c b/core/src/xmake/bloom_filter/bloom_filter_data.c
new file mode 100644
index 000000000..139040b70
--- /dev/null
+++ b/core/src/xmake/bloom_filter/bloom_filter_data.c
@@ -0,0 +1,55 @@
+/*!A cross-platform build utility based on Lua
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file bloom_filter_data.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "bloom_filter_data"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_bloom_filter_data(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // is pointer?
+ if (!xm_lua_ispointer(lua, 1))
+ return 0;
+
+ // get the bloom filter
+ tb_bloom_filter_ref_t filter = (tb_bloom_filter_ref_t)xm_lua_topointer(lua, 1);
+ tb_check_return_val(filter, 0);
+
+ // get data
+ tb_pointer_t data = (tb_pointer_t)tb_bloom_filter_data(filter);
+ if (data) xm_lua_pushpointer(lua, data);
+ else lua_pushnil(lua);
+ return 1;
+}
+
diff --git a/core/src/xmake/bloom_filter/bloom_filter_data_set.c b/core/src/xmake/bloom_filter/bloom_filter_data_set.c
new file mode 100644
index 000000000..330ba393e
--- /dev/null
+++ b/core/src/xmake/bloom_filter/bloom_filter_data_set.c
@@ -0,0 +1,66 @@
+/*!A cross-platform build utility based on Lua
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file bloom_filter_data_set.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "bloom_filter_data_set"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_bloom_filter_data_set(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // is pointer?
+ if (!xm_lua_ispointer(lua, 1))
+ return 0;
+
+ // get the bloom filter
+ tb_bloom_filter_ref_t filter = (tb_bloom_filter_ref_t)xm_lua_topointer(lua, 1);
+ tb_check_return_val(filter, 0);
+
+ // get data and size
+ tb_size_t size = 0;
+ tb_byte_t const* data = tb_null;
+ if (lua_isnumber(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2);
+ if (lua_isnumber(lua, 3)) size = (tb_size_t)lua_tonumber(lua, 3);
+ if (!data || !size)
+ {
+ lua_pushinteger(lua, -1);
+ lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size);
+ return 2;
+ }
+
+ // set data
+ tb_bool_t ok = tb_bloom_filter_data_set(filter, data, size);
+ lua_pushboolean(lua, ok);
+ return 1;
+}
+
diff --git a/core/src/xmake/bloom_filter/bloom_filter_size.c b/core/src/xmake/bloom_filter/bloom_filter_size.c
new file mode 100644
index 000000000..03dcefc17
--- /dev/null
+++ b/core/src/xmake/bloom_filter/bloom_filter_size.c
@@ -0,0 +1,55 @@
+/*!A cross-platform build utility based on Lua
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file bloom_filter_size.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "bloom_filter_size"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_bloom_filter_size(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // is pointer?
+ if (!xm_lua_ispointer(lua, 1))
+ return 0;
+
+ // get the bloom filter
+ tb_bloom_filter_ref_t filter = (tb_bloom_filter_ref_t)xm_lua_topointer(lua, 1);
+ tb_check_return_val(filter, 0);
+
+ // get size
+ tb_size_t size = tb_bloom_filter_size(filter);
+ lua_pushinteger(lua, (tb_int_t)size);
+ return 1;
+}
+
+
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index 992fb0cca..6fb35b207 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -209,6 +209,10 @@ tb_int_t xm_lz4_decompress_stream_close(lua_State* lua);
// the bloom filter functions
tb_int_t xm_bloom_filter_open(lua_State* lua);
tb_int_t xm_bloom_filter_close(lua_State* lua);
+tb_int_t xm_bloom_filter_clear(lua_State* lua);
+tb_int_t xm_bloom_filter_data(lua_State* lua);
+tb_int_t xm_bloom_filter_size(lua_State* lua);
+tb_int_t xm_bloom_filter_data_set(lua_State* lua);
// the windows functions
#ifdef TB_CONFIG_OS_WINDOWS
@@ -448,9 +452,13 @@ static luaL_Reg const g_lz4_functions[] =
// the bloom filter functions
static luaL_Reg const g_bloom_filter_functions[] =
{
- { "open", xm_bloom_filter_open }
-, { "close", xm_bloom_filter_close }
-, { tb_null, tb_null }
+ { "open", xm_bloom_filter_open }
+, { "close", xm_bloom_filter_close }
+, { "clear", xm_bloom_filter_clear }
+, { "data", xm_bloom_filter_data }
+, { "size", xm_bloom_filter_size }
+, { "data_set", xm_bloom_filter_data_set }
+, { tb_null, tb_null }
};
// the string functions
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index bb1c21582..55e04fc00 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -150,7 +150,11 @@ xmake_C_FILES += \
lz4/decompress_stream_write \
lz4/decompress_stream_close \
bloom_filter/bloom_filter_open \
- bloom_filter/bloom_filter_close
+ bloom_filter/bloom_filter_close \
+ bloom_filter/bloom_filter_clear \
+ bloom_filter/bloom_filter_data \
+ bloom_filter/bloom_filter_size \
+ bloom_filter/bloom_filter_data_set
iswin =
ifeq ($(PLAT),windows)
diff --git a/xmake/core/base/bytes.lua b/xmake/core/base/bytes.lua
index daf51bc81..1103c8f6a 100644
--- a/xmake/core/base/bytes.lua
+++ b/xmake/core/base/bytes.lua
@@ -47,7 +47,8 @@ function _instance.new(...)
local instance = table.inherit(_instance)
if type(arg1) == "number" then
local size = arg1
- if type(arg2) == "cdata" then
+ local arg2_type = type(arg2)
+ if arg2_type == "cdata" or arg2_type == "userdata" then
-- bytes(size, ptr [, manage]): mounts buffer on existing storage (manage memory or not)
local ptr = arg2
local manage = arg3
@@ -62,9 +63,9 @@ function _instance.new(...)
-- bytes(size[, init]): allocates a buffer of given size
local init
if arg2 then
- if type(arg2) == "number" then
+ if arg2_type == "number" then
init = arg2
- elseif type(arg2) == "string" then
+ elseif arg2_type == "string" then
init = arg2:byte()
else
os.raise("invalid arguments #2 for bytes(size, ...), cdata, string, number or nil expected!")