mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 02:47:56 +08:00
add bitmap class for bit operation
This commit is contained in:
parent
28f805981e
commit
5b0cdc1fc9
@ -1,6 +1,9 @@
|
||||
修改历史列表:
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
490) 2017.8.23
|
||||
490.1) feature: 在 stdlib/ 目录下新增 bitmap 类,用于位映射操作
|
||||
|
||||
489) 2017.8.18
|
||||
489.1) feature: 增加原子操作类 atomic
|
||||
489.2) samples/atomic: 增加测试原子操作的例子
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "stdlib/dbuf_pool.hpp"
|
||||
#include "stdlib/mbox.hpp"
|
||||
#include "stdlib/atomic.hpp"
|
||||
#include "stdlib/bitmap.hpp"
|
||||
|
||||
#include "serialize/gsoner.hpp"
|
||||
|
||||
|
97
lib_acl_cpp/include/acl_cpp/stdlib/bitmap.hpp
Normal file
97
lib_acl_cpp/include/acl_cpp/stdlib/bitmap.hpp
Normal file
@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
namespace acl {
|
||||
|
||||
/**
|
||||
* @author wanghaibin@qiyi.com
|
||||
* @date 2017-08-16
|
||||
*/
|
||||
|
||||
class bitmap
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* 构造函数
|
||||
* @param buf {const void*} 源数据内存位映射区
|
||||
* @param len {size_} buf 位映射内存区中被置位的数量
|
||||
*/
|
||||
bitmap(const void* buf, size_t len);
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param len {size_t} 最大容纳的位映射的数量
|
||||
*/
|
||||
bitmap(size_t len);
|
||||
|
||||
~bitmap();
|
||||
|
||||
/**
|
||||
* 将所给数值映射在位集合中
|
||||
* @param n {size_t}
|
||||
* @return {bool} 返回 true 表示添加成功,否则表示该值越界或已经存在
|
||||
*/
|
||||
bool set(size_t n);
|
||||
|
||||
/**
|
||||
* 判断所给数据是否已经被设置在位映射中
|
||||
* @param n {size_t}
|
||||
* @return {bool} 判断指定数值是否存在于位映射集合中
|
||||
*/
|
||||
bool isset(size_t n);
|
||||
|
||||
/**
|
||||
* 将指定数值从位集合中去除
|
||||
* @param n {size_t}
|
||||
* @return {bool} 返回 false 表示该值越界或不存在于位集合中
|
||||
*/
|
||||
bool unset(size_t n);
|
||||
|
||||
/**
|
||||
* 将bitmap信息拷贝到buf中
|
||||
* @param buf {void*}存放拷贝结果
|
||||
* @param len {size_t} buf的最大长度
|
||||
* @return {size_t} 返回成功拷贝的内存长度,返回 0 表示 buf 太小
|
||||
*/
|
||||
size_t tobuf(void* buf, size_t len);
|
||||
|
||||
/**
|
||||
* 从buf中设置当前bitmap信息
|
||||
* @param buf {const void*} 要设置bitmap信息
|
||||
* @param len {size_t} buf的长度
|
||||
* @return true 成功,false失败
|
||||
*/
|
||||
bool frombuf(const void* buf, size_t len);
|
||||
|
||||
/**
|
||||
* 重置当前的bitmap为 0
|
||||
*/
|
||||
void reset(void);
|
||||
|
||||
/**
|
||||
* 获取当前位映射存储空间的大小
|
||||
* @return {size_t}
|
||||
*/
|
||||
size_t size(void);
|
||||
|
||||
/**
|
||||
* 获取当前已经设置的个数
|
||||
* @return {size_t}
|
||||
*/
|
||||
size_t count(void);
|
||||
|
||||
/**
|
||||
* 当前bitmap是否已满
|
||||
* @return {bool}
|
||||
*/
|
||||
bool full(void);
|
||||
|
||||
private:
|
||||
unsigned char *bmp_;
|
||||
size_t size_;
|
||||
size_t count_;
|
||||
|
||||
//从新统计count数量
|
||||
void recount(void);
|
||||
};
|
||||
|
||||
} // namespace acl
|
@ -33,6 +33,7 @@ public:
|
||||
~thread_cond(void);
|
||||
|
||||
bool notify(void);
|
||||
bool notify_all(void);
|
||||
bool wait(long long microseconds = 0);
|
||||
|
||||
thread_mutex& get_mutex(void) const;
|
||||
|
@ -387,6 +387,9 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<File
|
||||
RelativePath=".\src\stdlib\atomic.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\stdlib\bitmap.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\stdlib\json.cpp">
|
||||
</File>
|
||||
@ -1066,6 +1069,9 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<File
|
||||
RelativePath=".\include\acl_cpp\stdlib\atomic.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\acl_cpp\stdlib\bitmap.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\acl_cpp\stdlib\charset_conv.hpp">
|
||||
</File>
|
||||
|
@ -973,6 +973,10 @@
|
||||
RelativePath=".\src\stdlib\atomic.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\stdlib\bitmap.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\stdlib\charset_conv.cpp"
|
||||
>
|
||||
@ -1755,6 +1759,10 @@
|
||||
RelativePath=".\include\acl_cpp\stdlib\atomic.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\acl_cpp\stdlib\bitmap.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\acl_cpp\stdlib\charset_conv.hpp"
|
||||
>
|
||||
|
@ -336,6 +336,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<ClCompile Include="src\smtp\mail_message.cpp" />
|
||||
<ClCompile Include="src\smtp\smtp_client.cpp" />
|
||||
<ClCompile Include="src\stdlib\atomic.cpp" />
|
||||
<ClCompile Include="src\stdlib\bitmap.cpp" />
|
||||
<ClCompile Include="src\stdlib\charset_conv.cpp" />
|
||||
<ClCompile Include="src\stdlib\dbuf_pool.cpp" />
|
||||
<ClCompile Include="src\stdlib\dns_service.cpp" />
|
||||
@ -513,6 +514,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<ClInclude Include="include\acl_cpp\smtp\mail_message.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\smtp\smtp_client.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\atomic.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\bitmap.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\charset_conv.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\dbuf_pool.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\dns_service.hpp" />
|
||||
|
@ -127,6 +127,9 @@
|
||||
<ClCompile Include="src\stdlib\atomic.cpp">
|
||||
<Filter>src\stdlib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\stdlib\bitmap.cpp">
|
||||
<Filter>src\stdlib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\stdlib\charset_conv.cpp">
|
||||
<Filter>src\stdlib</Filter>
|
||||
</ClCompile>
|
||||
@ -783,6 +786,9 @@
|
||||
<ClInclude Include="include\acl_cpp\stdlib\atomic.hpp">
|
||||
<Filter>include\stdlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\stdlib\bitmap.hpp">
|
||||
<Filter>include\stdlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\stdlib\charset_conv.hpp">
|
||||
<Filter>include\stdlib</Filter>
|
||||
</ClInclude>
|
||||
|
@ -530,6 +530,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<ClCompile Include="src\smtp\mail_message.cpp" />
|
||||
<ClCompile Include="src\smtp\smtp_client.cpp" />
|
||||
<ClCompile Include="src\stdlib\atomic.cpp" />
|
||||
<ClCompile Include="src\stdlib\bitmap.cpp" />
|
||||
<ClCompile Include="src\stdlib\charset_conv.cpp" />
|
||||
<ClCompile Include="src\stdlib\dbuf_pool.cpp" />
|
||||
<ClCompile Include="src\stdlib\dns_service.cpp" />
|
||||
@ -707,6 +708,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<ClInclude Include="include\acl_cpp\smtp\mail_message.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\smtp\smtp_client.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\atomic.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\bitmap.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\charset_conv.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\dbuf_pool.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\dns_service.hpp" />
|
||||
|
@ -124,6 +124,12 @@
|
||||
<ClCompile Include="src\stdlib\atomic.cpp">
|
||||
<Filter>Source Files\stdlib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\stdlib\bitmap.cpp">
|
||||
<Filter>Source Files\stdlib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\stdlib\bitmap.cpp">
|
||||
<Filter>Source Files\stdlib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\stdlib\charset_conv.cpp">
|
||||
<Filter>Source Files\stdlib</Filter>
|
||||
</ClCompile>
|
||||
@ -777,6 +783,12 @@
|
||||
<ClInclude Include="include\acl_cpp\stdlib\atomic.hpp">
|
||||
<Filter>Header Files\stdlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\stdlib\bitmap.hpp">
|
||||
<Filter>Header Files\stdlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\stdlib\bitmap.hpp">
|
||||
<Filter>Header Files\stdlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\stdlib\charset_conv.hpp">
|
||||
<Filter>Header Files\stdlib</Filter>
|
||||
</ClInclude>
|
||||
|
@ -530,6 +530,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<ClCompile Include="src\smtp\mail_message.cpp" />
|
||||
<ClCompile Include="src\smtp\smtp_client.cpp" />
|
||||
<ClCompile Include="src\stdlib\atomic.cpp" />
|
||||
<ClCompile Include="src\stdlib\bitmap.cpp" />
|
||||
<ClCompile Include="src\stdlib\charset_conv.cpp" />
|
||||
<ClCompile Include="src\stdlib\dbuf_pool.cpp" />
|
||||
<ClCompile Include="src\stdlib\dns_service.cpp" />
|
||||
@ -707,6 +708,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<ClInclude Include="include\acl_cpp\smtp\mail_message.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\smtp\smtp_client.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\atomic.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\bitmap.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\charset_conv.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\dbuf_pool.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\dns_service.hpp" />
|
||||
|
@ -124,6 +124,9 @@
|
||||
<ClCompile Include="src\stdlib\atomic.cpp">
|
||||
<Filter>Source Files\stdlib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\stdlib\bitmap.cpp">
|
||||
<Filter>Source Files\stdlib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\stdlib\charset_conv.cpp">
|
||||
<Filter>Source Files\stdlib</Filter>
|
||||
</ClCompile>
|
||||
@ -777,6 +780,9 @@
|
||||
<ClInclude Include="include\acl_cpp\stdlib\atomic.hpp">
|
||||
<Filter>Header Files\stdlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\stdlib\bitmap.hpp">
|
||||
<Filter>Header Files\stdlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\stdlib\charset_conv.hpp">
|
||||
<Filter>Header Files\stdlib</Filter>
|
||||
</ClInclude>
|
||||
|
@ -530,6 +530,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<ClCompile Include="src\smtp\mail_message.cpp" />
|
||||
<ClCompile Include="src\smtp\smtp_client.cpp" />
|
||||
<ClCompile Include="src\stdlib\atomic.cpp" />
|
||||
<ClCompile Include="src\stdlib\bitmap.cpp" />
|
||||
<ClCompile Include="src\stdlib\charset_conv.cpp" />
|
||||
<ClCompile Include="src\stdlib\dbuf_pool.cpp" />
|
||||
<ClCompile Include="src\stdlib\dns_service.cpp" />
|
||||
@ -707,6 +708,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<ClInclude Include="include\acl_cpp\smtp\mail_message.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\smtp\smtp_client.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\atomic.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\bitmap.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\charset_conv.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\dbuf_pool.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\stdlib\dns_service.hpp" />
|
||||
|
@ -124,6 +124,9 @@
|
||||
<ClCompile Include="src\stdlib\atomic.cpp">
|
||||
<Filter>Source Files\stdlib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\stdlib\bitmap.cpp">
|
||||
<Filter>Source Files\stdlib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\stdlib\charset_conv.cpp">
|
||||
<Filter>Source Files\stdlib</Filter>
|
||||
</ClCompile>
|
||||
@ -777,6 +780,9 @@
|
||||
<ClInclude Include="include\acl_cpp\stdlib\atomic.hpp">
|
||||
<Filter>Header Files\stdlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\stdlib\bitmap.hpp">
|
||||
<Filter>Header Files\stdlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\stdlib\charset_conv.hpp">
|
||||
<Filter>Header Files\stdlib</Filter>
|
||||
</ClInclude>
|
||||
|
@ -51,6 +51,11 @@ bool thread_cond::notify(void)
|
||||
return acl_pthread_cond_signal(cond_) == 0;
|
||||
}
|
||||
|
||||
bool thread_cond::notify_all(void)
|
||||
{
|
||||
return acl_pthread_cond_broadcast(cond_) == 0;
|
||||
}
|
||||
|
||||
bool thread_cond::wait(long long microseconds /* = 0 */)
|
||||
{
|
||||
#define SEC_TO_NS 1000000000 // nanoseconds per second
|
||||
|
Loading…
Reference in New Issue
Block a user