diff options
| author | ruki <[email protected]> | 2022-05-21 21:37:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-21 21:37:20 +0800 |
| commit | 56f6d6a37fbbcd011fc99441f30df3ce24b7c3f6 (patch) | |
| tree | 481bb6a10379ac016de705e8d9140388d4678bc5 /core/src | |
| parent | dbc34e84e8cbdaa3b2482e825b44aec311eafc1b (diff) | |
add bloom filter get and set
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/bloom_filter/bloom_filter_get.c | 59 | ||||
| -rw-r--r-- | core/src/xmake/bloom_filter/bloom_filter_set.c | 58 | ||||
| -rw-r--r-- | core/src/xmake/engine.c | 4 | ||||
| -rw-r--r-- | core/src/xmake/makefile | 2 |
4 files changed, 123 insertions, 0 deletions
diff --git a/core/src/xmake/bloom_filter/bloom_filter_get.c b/core/src/xmake/bloom_filter/bloom_filter_get.c new file mode 100644 index 000000000..1b5638836 --- /dev/null +++ b/core/src/xmake/bloom_filter/bloom_filter_get.c @@ -0,0 +1,59 @@ +/*!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_get.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "bloom_filter_get" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_bloom_filter_get(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 item + tb_char_t const* item = luaL_checkstring(lua, 2); + tb_assert_and_check_return_val(item, 0); + + // get item + tb_bool_t ok = tb_bloom_filter_get(filter, item); + lua_pushboolean(lua, ok); + return 1; +} + + diff --git a/core/src/xmake/bloom_filter/bloom_filter_set.c b/core/src/xmake/bloom_filter/bloom_filter_set.c new file mode 100644 index 000000000..20c10f667 --- /dev/null +++ b/core/src/xmake/bloom_filter/bloom_filter_set.c @@ -0,0 +1,58 @@ +/*!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_set.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "bloom_filter_set" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_bloom_filter_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 item + tb_char_t const* item = luaL_checkstring(lua, 2); + tb_assert_and_check_return_val(item, 0); + + // set item + tb_bool_t ok = tb_bloom_filter_set(filter, item); + lua_pushboolean(lua, ok); + return 1; +} + diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 6fb35b207..d275c21f8 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -212,6 +212,8 @@ 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_get(lua_State* lua); +tb_int_t xm_bloom_filter_set(lua_State* lua); tb_int_t xm_bloom_filter_data_set(lua_State* lua); // the windows functions @@ -457,6 +459,8 @@ static luaL_Reg const g_bloom_filter_functions[] = , { "clear", xm_bloom_filter_clear } , { "data", xm_bloom_filter_data } , { "size", xm_bloom_filter_size } +, { "get", xm_bloom_filter_get } +, { "set", xm_bloom_filter_set } , { "data_set", xm_bloom_filter_data_set } , { tb_null, tb_null } }; diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index 55e04fc00..996b76578 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -154,6 +154,8 @@ xmake_C_FILES += \ bloom_filter/bloom_filter_clear \ bloom_filter/bloom_filter_data \ bloom_filter/bloom_filter_size \ + bloom_filter/bloom_filter_get \ + bloom_filter/bloom_filter_set \ bloom_filter/bloom_filter_data_set iswin = |
