2019-07-28 10:31:56 +08:00
|
|
|
|
#pragma once
|
2019-05-09 13:57:51 +08:00
|
|
|
|
#include "noncopyable.hpp"
|
2018-08-19 15:31:26 +08:00
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
2019-05-09 13:57:51 +08:00
|
|
|
|
class bitmap : public noncopyable
|
2018-08-19 15:31:26 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|
|
|
|
* @param buf {const void*} Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>λӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_} buf λӳ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
|
|
|
|
bitmap(const void* buf, size_t len);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD>λӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
|
|
|
|
bitmap(size_t len);
|
|
|
|
|
|
2020-05-19 12:03:24 +08:00
|
|
|
|
~bitmap(void);
|
2018-08-19 15:31:26 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @param n {size_t}
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ֵԽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
|
|
|
|
bool bit_set(size_t n);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @param n {size_t}
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* @return {bool} <EFBFBD>ж<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λӳ<EFBFBD>伯<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
2020-05-19 12:03:24 +08:00
|
|
|
|
bool bit_isset(size_t n) const;
|
2018-08-19 15:31:26 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @param n {size_t}
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ֵԽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
|
|
|
|
bool bit_unset(size_t n);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>bitmap<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>buf<EFBFBD><EFBFBD>
|
|
|
|
|
* @param buf {void*}<EFBFBD><EFBFBD><EFBFBD>ſ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_t} buf<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {size_t} <EFBFBD><EFBFBD><EFBFBD>سɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ泤<EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 <EFBFBD><EFBFBD>ʾ buf ̫С
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
2020-05-19 12:03:24 +08:00
|
|
|
|
size_t tobuf(void* buf, size_t len) const;
|
2018-08-19 15:31:26 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>buf<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰbitmap<EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
* @param buf {const void*} Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>bitmap<EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
* @param len {size_t} buf<EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return true <EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>falseʧ<EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
|
|
|
|
bool frombuf(const void* buf, size_t len);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD>bitmapΪ 0
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
|
|
|
|
void reset(void);
|
|
|
|
|
|
|
|
|
|
/**
|
2020-05-19 12:03:24 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ǰλӳ<EFBFBD><EFBFBD><EFBFBD>洢<EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ洢<EFBFBD><EFBFBD>λ<EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @return {size_t}
|
|
|
|
|
*/
|
2020-05-19 12:03:24 +08:00
|
|
|
|
size_t size(void) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD>洢<EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD>ֽڣ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
size_t space(void) const;
|
2018-08-19 15:31:26 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ǰ<EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĸ<EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @return {size_t}
|
|
|
|
|
*/
|
2020-05-19 12:03:24 +08:00
|
|
|
|
size_t count(void) const;
|
2018-08-19 15:31:26 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>ǰbitmap<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
2020-05-19 12:03:24 +08:00
|
|
|
|
bool full(void) const;
|
2018-08-19 15:31:26 +08:00
|
|
|
|
|
2020-05-19 18:20:48 +08:00
|
|
|
|
public:
|
|
|
|
|
const unsigned char* get_bmp(void) const {
|
|
|
|
|
return bmp_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned char* get_bmp(void) {
|
|
|
|
|
return bmp_;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-19 15:31:26 +08:00
|
|
|
|
private:
|
|
|
|
|
unsigned char *bmp_;
|
|
|
|
|
size_t size_;
|
|
|
|
|
size_t count_;
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3>count<6E><74><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
void recount(void);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|