count bug fix
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "Allocator.h"
|
#include "Allocator.h"
|
||||||
@@ -10,6 +11,8 @@
|
|||||||
|
|
||||||
namespace TinySTL{
|
namespace TinySTL{
|
||||||
|
|
||||||
|
//bitmap<61>ὫN<E1BDAB>ϵ<EFBFBD><CFB5><EFBFBD>8<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
|
||||||
|
//<2F><><EFBFBD><EFBFBD>bitmapʵ<70><CAB5><EFBFBD>ϻ<EFBFBD><CFBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bit<69><74><EFBFBD>Ǵ<EFBFBD><C7B4>ڵ<EFBFBD><DAB5><EFBFBD>N<EFBFBD><4E>
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
class bitmap{
|
class bitmap{
|
||||||
public:
|
public:
|
||||||
@@ -28,6 +31,7 @@ namespace TinySTL{
|
|||||||
size_t size() const{ return size_; }
|
size_t size() const{ return size_; }
|
||||||
//Returns whether the bit at position pos is set (i.e., whether it is one).
|
//Returns whether the bit at position pos is set (i.e., whether it is one).
|
||||||
bool test(size_t pos) const{
|
bool test(size_t pos) const{
|
||||||
|
THROW(pos);
|
||||||
const auto nth = getNth(pos);
|
const auto nth = getNth(pos);
|
||||||
const auto mth = getMth(pos);
|
const auto mth = getMth(pos);
|
||||||
uint8_t *ptr = start_ + nth;
|
uint8_t *ptr = start_ + nth;
|
||||||
@@ -88,6 +92,10 @@ namespace TinySTL{
|
|||||||
start_ = dataAllocator::allocate(n);
|
start_ = dataAllocator::allocate(n);
|
||||||
finish_ = uninitialized_fill_n(start_, n, val);
|
finish_ = uninitialized_fill_n(start_, n, val);
|
||||||
}
|
}
|
||||||
|
void THROW(size_t n)const{
|
||||||
|
if (!(0 <= n && n < size()))
|
||||||
|
throw std::out_of_range("Out Of Range");
|
||||||
|
}
|
||||||
};// end of bitmap
|
};// end of bitmap
|
||||||
|
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
@@ -96,7 +104,7 @@ namespace TinySTL{
|
|||||||
}
|
}
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
bitmap<N>& bitmap<N>::set(size_t pos, bool val){
|
bitmap<N>& bitmap<N>::set(size_t pos, bool val){
|
||||||
assert(pos >= 0);
|
THROW(pos);
|
||||||
const auto nth = getNth(pos);
|
const auto nth = getNth(pos);
|
||||||
const auto mth = getMth(pos);
|
const auto mth = getMth(pos);
|
||||||
uint8_t *ptr = start_ + nth;//get the nth uint8_t
|
uint8_t *ptr = start_ + nth;//get the nth uint8_t
|
||||||
@@ -119,6 +127,7 @@ namespace TinySTL{
|
|||||||
}
|
}
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
bitmap<N>& bitmap<N>::flip(size_t pos){
|
bitmap<N>& bitmap<N>::flip(size_t pos){
|
||||||
|
THROW(pos);
|
||||||
const auto nth = getNth(pos);
|
const auto nth = getNth(pos);
|
||||||
const auto mth = getMth(pos);
|
const auto mth = getMth(pos);
|
||||||
uint8_t *ptr = start_ + nth;
|
uint8_t *ptr = start_ + nth;
|
||||||
@@ -134,10 +143,11 @@ namespace TinySTL{
|
|||||||
uint8_t *ptr = start_;
|
uint8_t *ptr = start_;
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
for (; ptr != finish_; ++ptr){
|
for (; ptr != finish_; ++ptr){
|
||||||
uint8_t n = *ptr;
|
for (int i = 0; i != 8; ++i){
|
||||||
while (n){
|
uint8_t t = getMask(*ptr, i);
|
||||||
|
if (t){
|
||||||
++sum;
|
++sum;
|
||||||
n = n >> 1;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
|
|||||||
Reference in New Issue
Block a user