From 76af4f1e4bac17844cca3a923b3455914e7c613b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Thu, 25 Sep 2014 14:30:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90bitmap=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Bitmap.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/TinySTL/Bitmap.h b/TinySTL/Bitmap.h index 7952a6a..90fc075 100644 --- a/TinySTL/Bitmap.h +++ b/TinySTL/Bitmap.h @@ -1,8 +1,61 @@ #ifndef _BITMAP_H_ #define _BITMAP_H_ +#include +#include + +#include "Allocator.h" +#include "UninitializedFunctions.h" + namespace TinySTL{ + template + class bitmap{ + public: + typedef allocator dataAllocator; + private: + uint8_t *start_; + uint8_t *finish_; + const size_t size_; + enum EAlign{ ALIGN = 8 }; + public: + bitmap(); + explicit bitmap(const std::string& str);//TODO + + //Returns the number of bits in the bitset that are set (i.e., that have a value of one) + size_t count() const;//TODO + size_t size() const{ return size_; } + //Returns whether the bit at position pos is set (i.e., whether it is one). + bool test(size_t pos) const;//TODO + //Returns whether any of the bits is set (i.e., whether at least one bit in the bitset is set to one). + bool any() const;//TODO + //Returns whether none of the bits is set (i.e., whether all bits in the bitset have a value of zero). + bool none() const;//TODO + //Returns whether all of the bits in the bitset are set (to one). + bool all() const;//TODO + + bitset& set();//TODO + bitset& set(size_t pos, bool val = true);//TODO + bitset& reset();//TODO + bitset& reset(size_t pos);//TODO + bitset& flip();//TODO + bitset& flip(size_t pos);//TODO + + std::string to_string() const;//TODO + private: + size_t roundUp8(size_t bytes){ + return ((bytes + EAlign::ALIGN - 1) & ~(EAlign::ALIGN - 1)); + } + void allocateAndFillN(const size_t n, const uint8_t val){ + start_ = dataAllocator::allocate(n); + finish_ = uninitialized_fill_n(start_, n, val); + } + };// end of bitmap + + template + bitmap::bitmap() :size_(N){ + allocateAndFillN(size_, 0); + } } #endif \ No newline at end of file