value rename, use AllocCount instead of max_count

This commit is contained in:
2020-12-09 16:26:59 +08:00
parent 52d0077fa9
commit b3bbccfabc
5 changed files with 60 additions and 59 deletions

View File

@@ -13,13 +13,13 @@ namespace hgl
{
if(value<=0)
{
LOG_ERROR(OS_TEXT("ActiveChain缓冲区大小被设置<=0"));
LOG_ERROR(OS_TEXT("LRUCache缓冲区大小被设置<=0"));
value=3;
}
count=0;
max_count=value;
alloc_count=value;
start_item=nullptr;
end_item=nullptr;
@@ -32,14 +32,14 @@ namespace hgl
}
template<typename F,typename T>
void LRUCache<F,T>::SetMaxCount(int value)
void LRUCache<F,T>::Realloc(int value)
{
if(value<=0)
{
LOG_ERROR(OS_TEXT("ActiveChain缓冲区大小被设置<=0此次设置无效"));
LOG_ERROR(OS_TEXT("LRUCache缓冲区大小被设置<=0此次设置无效"));
}
else
max_count=value;
alloc_count=value;
}
template<typename F,typename T>
@@ -71,7 +71,7 @@ namespace hgl
#ifdef _DEBUG
if(count!=1)
{
LOG_ERROR(OS_TEXT("ActiveChain出错end_item=nullptr,count!=1"));
LOG_ERROR(OS_TEXT("LRUCache出错end_item=nullptr,count!=1"));
}
#endif//
start_item=nullptr; //如果end_item为空start_item也应该为空
@@ -90,7 +90,7 @@ namespace hgl
{
LruItem *temp;
while(count>=max_count)ClearEnd(); //满了,清除超出的数据
while(count>=alloc_count)ClearEnd(); //满了,清除超出的数据
temp=new LruItem;
temp->key=key;
@@ -111,7 +111,7 @@ namespace hgl
#ifdef _DEBUG //理由上end_item为NULL时应该是没有数据
if(count!=1)
{
LOG_ERROR(OS_TEXT("ActiveChain出错end_item=nullptr,count!=1"));
LOG_ERROR(OS_TEXT("LRUCache出错end_item=nullptr,count!=1"));
}
else
#endif//_DEBUG
@@ -202,7 +202,7 @@ namespace hgl
if(Find(key,value,mts))
return(true);
while(count>=max_count)ClearEnd(); //满了,清除超出的数据
while(count>=alloc_count)ClearEnd(); //满了,清除超出的数据
if(Create(key,value))
{

View File

@@ -30,7 +30,7 @@ namespace hgl
LruItem *start_item, //首数据
*end_item; //尾数据
int count,max_count;
int count,alloc_count;
protected:
@@ -45,10 +45,10 @@ namespace hgl
public:
const int GetCount ()const{return count;} ///<取得当前有多少数据
const int GetMaxCount ()const{return max_count;} ///<取得最大可以有多少数据
virtual void SetMaxCount (int); ///<设置最大可以有多少数据
int GetFreeCount()const{return max_count-count;} ///<取得当前缓冲区剩于量
const int GetCount ()const{return count;} ///<取得当前有多少数据
const int GetAllocCount ()const{return alloc_count;} ///<取得已分配空间容量
virtual void Realloc (int); ///<设置已分配空间容量
int GetFreeCount ()const{return alloc_count-count;} ///<取得当前缓冲区剩于量
public:

View File

@@ -79,16 +79,16 @@ namespace hgl
if(!items)
{
count=1;
max_count=1;
alloc_count=1;
items=hgl_align_malloc<T>(1);
return items;
}
else
{
max_count=power_to_2(count+1);
alloc_count=power_to_2(count+1);
items=(T *)hgl_align_realloc<T>(items,max_count);
items=(T *)hgl_align_realloc<T>(items,alloc_count);
++count;
return(items+(count-1));
@@ -106,14 +106,14 @@ namespace hgl
if(!items)
{
count=0;
max_count=1;
alloc_count=1;
items=hgl_align_malloc<T>(1);
}
else
{
max_count=power_to_2(count+1);
alloc_count=power_to_2(count+1);
items=(T *)hgl_align_realloc<T>(items,max_count);
items=(T *)hgl_align_realloc<T>(items,alloc_count);
}
memcpy(items+count,&data,sizeof(T));//items[count]=data;
@@ -135,14 +135,14 @@ namespace hgl
if(!items)
{
count=0;
max_count=power_to_2(n);
items=hgl_align_malloc<T>(max_count);
alloc_count=power_to_2(n);
items=hgl_align_malloc<T>(alloc_count);
}
else
{
max_count=power_to_2(count+n);
alloc_count=power_to_2(count+n);
items=(T *)hgl_align_realloc<T>(items,max_count);
items=(T *)hgl_align_realloc<T>(items,alloc_count);
}
T *p=items;
@@ -170,15 +170,15 @@ namespace hgl
if(!items)
{
count=0;
max_count=power_to_2(n);
alloc_count=power_to_2(n);
items=hgl_align_malloc<T>(max_count);
items=hgl_align_malloc<T>(alloc_count);
}
else
{
max_count=power_to_2(count+n);
alloc_count=power_to_2(count+n);
items=(T *)hgl_align_realloc<T>(items,max_count);
items=(T *)hgl_align_realloc<T>(items,alloc_count);
}
memcpy(items+count,data,n*sizeof(T));
@@ -196,7 +196,7 @@ namespace hgl
void List<T>::Clear()
{
count=0;
max_count=0;
alloc_count=0;
if(items)
{
@@ -394,15 +394,15 @@ namespace hgl
{
if(!items)
{
max_count=1;
alloc_count=1;
items=hgl_align_malloc<T>(max_count);
items=hgl_align_malloc<T>(alloc_count);
}
else
{
max_count=power_to_2(count+1);
alloc_count=power_to_2(count+1);
items=(T *)hgl_align_realloc<T>(items,max_count);
items=(T *)hgl_align_realloc<T>(items,alloc_count);
}
memmove(items+index+1,items+index,(count-index)*sizeof(T));
@@ -442,14 +442,14 @@ namespace hgl
template<typename T>
void List<T>::PreMalloc(int new_count)
{
if(max_count>=new_count)return;
if(alloc_count>=new_count)return;
max_count=power_to_2(new_count);
alloc_count=power_to_2(new_count);
if(!items)
items=hgl_align_malloc<T>(max_count);
items=hgl_align_malloc<T>(alloc_count);
else
items=(T *)hgl_align_realloc<T>(items,max_count);
items=(T *)hgl_align_realloc<T>(items,alloc_count);
}
template<typename T>

View File

@@ -14,23 +14,24 @@ namespace hgl
{
protected:
int count=0;
int max_count=0;
int count=0; ///<当前数据数量
int alloc_count=0; ///<当前已分配空间数量
T *items=nullptr;
public: //属性
int GetCount ()const{return count;} ///<取得列表内数据数
virtual void SetCount (int); ///<设置列表内数据数量
virtual void PreMalloc (int); ///<预分配指定数量的数据空间
T * GetData ()const{return items;} ///<提供原始数据项
int GetBytes ()const{return count*sizeof(T);} ///<取得原始数据总字节数
int GetAllocCount ()const{return alloc_count;} ///<取得已分配容
int GetCount ()const{return count;} ///<取得列表内数据数量
virtual void SetCount (int); ///<设置列表内数据数量
virtual void PreMalloc (int); ///<预分配指定数量的数据空间
T * GetData ()const{return items;} ///<提供原始数据
int GetBytes ()const{return count*sizeof(T);} ///<取得原始数据总字节数
T * GetBegin (){return (items&&count>0)?items:nullptr;} ///<取得第一个数据项指针
T * GetEnd (){return (items&&count>0)?items+count-1:nullptr;} ///<取得最后一个数据项指针
T * GetBegin (){return (items&&count>0)?items:nullptr;} ///<取得第一个数据项指针
T * GetEnd (){return (items&&count>0)?items+count-1:nullptr;} ///<取得最后一个数据项指针
T * begin()const{return items;}
T * end()const{return items+count;}
T * begin ()const{return items;}
T * end ()const{return items+count;}
public: //方法

View File

@@ -21,15 +21,15 @@ namespace hgl
// {
// if(!this->items)
// {
// this->max_count=1;
// this->alloc_count=1;
// this->items=(T **)hgl_align_malloc<T *>(1);
// }
// else
// {
// if(this->count>=this->max_count)
// this->max_count<<=1;
// if(this->count>=this->alloc_count)
// this->alloc_count<<=1;
//
// this->items=(T **)hgl_realloc(this->items,this->max_count*sizeof(T *));
// this->items=(T **)hgl_realloc(this->items,this->alloc_count*sizeof(T *));
// }
//
// return(this->items[this->count++]=CreateObject());
@@ -45,10 +45,10 @@ namespace hgl
//
// if(index<this->count)
// {
// if(this->count>=this->max_count)
// this->max_count<<=1;
// if(this->count>=this->alloc_count)
// this->alloc_count<<=1;
//
// this->items=(T **)hgl_realloc(this->items,this->max_count*sizeof(T *));
// this->items=(T **)hgl_realloc(this->items,this->alloc_count*sizeof(T *));
//
// memmove(this->items+index+1,this->items+index,(this->count-index)*sizeof(T *));
//
@@ -217,13 +217,13 @@ namespace hgl
}
else
{
this->max_count=power_to_2(new_count);
this->alloc_count=power_to_2(new_count);
if(this->items)
{
if(new_count>this->count)
{
this->items=(T **)hgl_realloc(this->items,this->max_count*sizeof(T *));
this->items=(T **)hgl_realloc(this->items,this->alloc_count*sizeof(T *));
// for(;this->count<new_count;this->count++)
// this->items[this->count]=CreateObject();
@@ -233,12 +233,12 @@ namespace hgl
while(this->count-->new_count)
DeleteObject(this->items[this->count]);
this->items=(T **)hgl_realloc(this->items,this->max_count*sizeof(T *));
this->items=(T **)hgl_realloc(this->items,this->alloc_count*sizeof(T *));
}
}
// else
// {
// this->items=(T **)hgl_align_malloc<T *>(this->max_count);
// this->items=(T **)hgl_align_malloc<T *>(this->alloc_count);
//
// while(new_count--)
// this->items[this->count++]=CreateObject();