Adjust int to int64 in many templates.
This commit is contained in:
parent
f2519a16be
commit
d63fb86ebd
64
inc/hgl/type/AccumMemoryManager.h
Normal file
64
inc/hgl/type/AccumMemoryManager.h
Normal file
@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/type/DataArray.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
/**
|
||||
* 累计内存管理<br>
|
||||
* 用于不断分配固定容量的内存块,但不动态调整,最后统一释放的情况。
|
||||
*/
|
||||
class AccumMemoryManager
|
||||
{
|
||||
public:
|
||||
|
||||
struct Block
|
||||
{
|
||||
int64 offset;
|
||||
int64 size;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
int64 total_bytes=0; ///<总字节数
|
||||
|
||||
DataArray<AccumMemoryManager::Block> block_list;
|
||||
DataArray<char> data_array; ///<数据
|
||||
|
||||
public:
|
||||
|
||||
AccumMemoryManager()=default;
|
||||
~AccumMemoryManager()=default;
|
||||
|
||||
const int64 GetTotalBytes()const{return total_bytes;}
|
||||
const int64 GetBlockCount()const{return block_list.GetCount();}
|
||||
|
||||
const void *Acquire(const int64 size)
|
||||
{
|
||||
if(size<=0)return(nullptr);
|
||||
|
||||
Block b;
|
||||
|
||||
b.offset=total_bytes;
|
||||
b.size=size;
|
||||
|
||||
data_array.AddCount(size);
|
||||
|
||||
return data_array.GetPointer(b.offset);
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
total_bytes=0;
|
||||
block_list.Clear();
|
||||
data_array.Clear();
|
||||
}
|
||||
|
||||
void Free()
|
||||
{
|
||||
total_bytes=0;
|
||||
block_list.Free();
|
||||
data_array.Free();
|
||||
}
|
||||
};//class AccumMemoryManager
|
||||
}//namespace
|
@ -35,14 +35,14 @@ namespace hgl
|
||||
/**
|
||||
* 查找数据在无序阵列中的位置
|
||||
*/
|
||||
template<typename T> static int FindDataPositionInArray(const T *data_list,const int count,const T &data)
|
||||
template<typename T> static int FindDataPositionInArray(const T *data_list,const int64 count,const T &data)
|
||||
{
|
||||
if(!data_list)return(-1);
|
||||
if(count<=0)return(-1);
|
||||
|
||||
const T *p=data_list;
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
for(int64 i=0;i<count;i++)
|
||||
{
|
||||
//if(*p==data)
|
||||
if(!memcmp(p,&data,sizeof(T)))
|
||||
@ -54,7 +54,7 @@ namespace hgl
|
||||
return -1;
|
||||
}
|
||||
|
||||
template<typename T,typename O> static int FindDataPositionInArray(const T &data_list,const O &data)
|
||||
template<typename T,typename O> static int64 FindDataPositionInArray(const T &data_list,const O &data)
|
||||
{
|
||||
return FindDataPositionInArray(data_list.GetData(),data_list.GetCount(),data);
|
||||
}
|
||||
@ -62,10 +62,10 @@ namespace hgl
|
||||
/**
|
||||
* 查找数据在有序阵列中的位置
|
||||
*/
|
||||
template<typename T> static int FindDataPositionInSortedArray(const T *data_array,const int count,const T &flag)
|
||||
template<typename T> static int64 FindDataPositionInSortedArray(const T *data_array,const int64 count,const T &flag)
|
||||
{
|
||||
int left=0,right=count-1; //使用left,right而不使用min,max是为了让代码能够更好的阅读。
|
||||
int mid;
|
||||
int64 left=0,right=count-1; //使用left,right而不使用min,max是为了让代码能够更好的阅读。
|
||||
int64 mid;
|
||||
|
||||
while(left<=right)
|
||||
{
|
||||
@ -91,7 +91,7 @@ namespace hgl
|
||||
return(-1);
|
||||
}
|
||||
|
||||
template<typename T,typename O> static int FindDataPositionInSortedArray(const T &data_array,const O &flag)
|
||||
template<typename T,typename O> static int64 FindDataPositionInSortedArray(const T &data_array,const O &flag)
|
||||
{
|
||||
return FindDataPositionInSortedArray(data_array.GetData(),data_array.GetCount(),flag);
|
||||
}
|
||||
@ -104,10 +104,10 @@ namespace hgl
|
||||
* @param flag 要查找的数据
|
||||
* @return 这个数据是否已经存在
|
||||
*/
|
||||
template<typename T> static bool FindInsertPositionInSortedArray(int *pos,const T *data_array,const int count,const T &flag)
|
||||
template<typename T> static bool FindInsertPositionInSortedArray(int64 *pos,const T *data_array,const int64 count,const T &flag)
|
||||
{
|
||||
int left=0,right=count-1;
|
||||
int mid;
|
||||
int64 left=0,right=count-1;
|
||||
int64 mid;
|
||||
|
||||
while(left<=right)
|
||||
{
|
||||
@ -182,7 +182,7 @@ namespace hgl
|
||||
return(false);
|
||||
}
|
||||
|
||||
template<typename T,typename O> static bool FindInsertPositionInSortedArray(int *pos,const T &data_array,const O &flag)
|
||||
template<typename T,typename O> static bool FindInsertPositionInSortedArray(int64 *pos,const T &data_array,const O &flag)
|
||||
{
|
||||
return FindInsertPositionInSortedArray(pos,data_array.GetData(),data_array.GetCount(),flag);
|
||||
}
|
||||
|
@ -8,24 +8,24 @@ namespace hgl
|
||||
*/
|
||||
class ArrayRearrangeHelper
|
||||
{
|
||||
int data_count; ///<数据总量
|
||||
int left_count; ///<剩余数量
|
||||
int data_offset; ///<当前访问偏移
|
||||
int64 data_count; ///<数据总量
|
||||
int64 left_count; ///<剩余数量
|
||||
int64 data_offset; ///<当前访问偏移
|
||||
|
||||
int field_count; //分段数量
|
||||
int64 field_count; ///<分段数量
|
||||
|
||||
struct Field
|
||||
{
|
||||
int start;
|
||||
int count;
|
||||
int64 start;
|
||||
int64 count;
|
||||
};
|
||||
|
||||
Field *field_list;
|
||||
int field_index;
|
||||
int64 field_index;
|
||||
|
||||
public:
|
||||
|
||||
ArrayRearrangeHelper(int dc,int fc)
|
||||
ArrayRearrangeHelper(int64 dc,int64 fc)
|
||||
{
|
||||
data_count=dc;
|
||||
left_count=dc;
|
||||
@ -45,7 +45,7 @@ namespace hgl
|
||||
/**
|
||||
* 添加一个分段
|
||||
*/
|
||||
bool AddField(int count)
|
||||
bool AddField(int64 count)
|
||||
{
|
||||
if(count<0)return(false);
|
||||
if(count>left_count)return(false);
|
||||
@ -63,9 +63,9 @@ namespace hgl
|
||||
/**
|
||||
* 添加多个分段
|
||||
*/
|
||||
bool AddField(const std::initializer_list<int> &count_list)
|
||||
bool AddField(const std::initializer_list<int64> &count_list)
|
||||
{
|
||||
for(const int count:count_list)
|
||||
for(const int64 count:count_list)
|
||||
if(!AddField(count))
|
||||
return(false);
|
||||
|
||||
@ -100,7 +100,7 @@ namespace hgl
|
||||
* 重新排列数据到一个新的数组中
|
||||
*/
|
||||
template<typename T>
|
||||
bool Rearrange(T *new_array,const T *old_array,const int *index)
|
||||
bool Rearrange(T *new_array,const T *old_array,const int64 *index)
|
||||
{
|
||||
if(!Finish())
|
||||
return(false);
|
||||
@ -108,7 +108,7 @@ namespace hgl
|
||||
T *p=new_array;
|
||||
Field *f;
|
||||
|
||||
for(int i=0;i<field_index;i++)
|
||||
for(int64 i=0;i<field_index;i++)
|
||||
{
|
||||
if(*index<0||*index>=field_index)
|
||||
return(false);
|
||||
@ -125,20 +125,23 @@ namespace hgl
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Rearrange(T *new_array,const T *old_array,const std::initializer_list<int> &index)
|
||||
bool Rearrange(T *new_array,const T *old_array,const std::initializer_list<int64> &index)
|
||||
{
|
||||
return Rearrange(new_array,old_array,index.begin());
|
||||
}
|
||||
};//class ArrayRearrangeHelper
|
||||
|
||||
template<typename T>
|
||||
inline bool ArrayRearrange(T *new_array,const T *old_array,const int count,const std::initializer_list<int> &field_list,const std::initializer_list<int> &index)
|
||||
inline bool ArrayRearrange( T *new_array,
|
||||
const T *old_array,const int64 count,
|
||||
const std::initializer_list<int64> &field_list,
|
||||
const std::initializer_list<int64> &index)
|
||||
{
|
||||
int field_count=(int)field_list.size();
|
||||
int64 field_count=(int)field_list.size();
|
||||
|
||||
int total=0;
|
||||
int64 total=0;
|
||||
|
||||
for(const int fc:field_list)total+=fc;
|
||||
for(const int64 fc:field_list)total+=fc;
|
||||
|
||||
if(total<count)
|
||||
++field_count;
|
||||
|
@ -13,15 +13,15 @@ namespace hgl
|
||||
protected:
|
||||
|
||||
T *items;
|
||||
int count; ///<当前数据数量
|
||||
int alloc_count; ///<已分配的数据数量
|
||||
int64 count; ///<当前数据数量
|
||||
int64 alloc_count; ///<已分配的数据数量
|
||||
|
||||
public:
|
||||
|
||||
int GetCount ()const{return count;} ///<取得数据数量(注:非字节数)
|
||||
const int GetAllocCount ()const{return alloc_count;} ///<取得已分配的阵列大小(注:非字节数)
|
||||
const int GetBytes ()const{return count*sizeof(T);} ///<取得阵列已使用的字节数
|
||||
const int GetAllocBytes ()const{return alloc_count*sizeof(T);} ///<取得阵列已分配空间字节数
|
||||
int64 GetCount ()const{return count;} ///<取得数据数量(注:非字节数)
|
||||
const int64 GetAllocCount ()const{return alloc_count;} ///<取得已分配的阵列大小(注:非字节数)
|
||||
const int64 GetBytes ()const{return count*sizeof(T);} ///<取得阵列已使用的字节数
|
||||
const int64 GetAllocBytes ()const{return alloc_count*sizeof(T);} ///<取得阵列已分配空间字节数
|
||||
|
||||
const bool IsEmpty ()const{return(count==0);} ///<是否为空
|
||||
|
||||
@ -39,7 +39,7 @@ namespace hgl
|
||||
/**
|
||||
* 分配指定空间出来,供未来使用
|
||||
*/
|
||||
bool Alloc(int size)
|
||||
bool Alloc(int64 size)
|
||||
{
|
||||
if(size<=alloc_count)
|
||||
return(true);
|
||||
@ -59,7 +59,7 @@ namespace hgl
|
||||
* @param size 阵列长度
|
||||
* @return 设置成功后的阵列长度
|
||||
*/
|
||||
int SetCount(int size) ///<设置阵列长度(注:非字节数)
|
||||
int64 SetCount(int64 size) ///<设置阵列长度(注:非字节数)
|
||||
{
|
||||
Alloc(size);
|
||||
|
||||
@ -72,7 +72,7 @@ namespace hgl
|
||||
* @param size 增加的长度
|
||||
* @return 增加后的阵列长度
|
||||
*/
|
||||
int AddCount(int size)
|
||||
int64 AddCount(int64 size)
|
||||
{
|
||||
return SetCount(count+size);
|
||||
}
|
||||
@ -86,7 +86,7 @@ namespace hgl
|
||||
alloc_count=0;
|
||||
}
|
||||
|
||||
DataArray(int size)
|
||||
DataArray(int64 size)
|
||||
{
|
||||
if(size<=0)
|
||||
items=nullptr;
|
||||
@ -149,22 +149,22 @@ namespace hgl
|
||||
return items;
|
||||
}
|
||||
|
||||
T &operator[](int n)
|
||||
T &operator[](int64 n)
|
||||
{
|
||||
return items[n];
|
||||
}
|
||||
|
||||
const T &operator[](int n)const
|
||||
const T &operator[](int64 n)const
|
||||
{
|
||||
return items[n];
|
||||
}
|
||||
|
||||
T *GetPointer(int n)const
|
||||
T *GetPointer(int64 n)const
|
||||
{
|
||||
return (n<0||n>=count)?nullptr:items+n;
|
||||
}
|
||||
|
||||
const bool ReadAt(T &obj,int const index)const
|
||||
const bool ReadAt(T &obj,int64 const index)const
|
||||
{
|
||||
if(index<0||index>=count)return(false);
|
||||
|
||||
@ -172,7 +172,7 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
const bool ReadAt(T *obj,int const start,const int num)const
|
||||
const bool ReadAt(T *obj,const int64 start,const int64 num)const
|
||||
{
|
||||
if(!obj||start<0||start+num>count)return(false);
|
||||
|
||||
@ -180,7 +180,7 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
const bool WriteAt(const T &obj,const int index)
|
||||
const bool WriteAt(const T &obj,const int64 index)
|
||||
{
|
||||
if(index<0||index>=count)return(false);
|
||||
|
||||
@ -188,7 +188,7 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
const bool WriteAt(const T *obj,const int start,const int num)
|
||||
const bool WriteAt(const T *obj,const int64 start,const int64 num)
|
||||
{
|
||||
if(!obj||start<0||start+num>count)return(false);
|
||||
|
||||
@ -214,7 +214,7 @@ namespace hgl
|
||||
|
||||
void operator = (const std::initializer_list<T> &l)
|
||||
{
|
||||
SetCount((int)l.size());
|
||||
SetCount((int64)l.size());
|
||||
|
||||
hgl_cpy<T>(items,l.begin(),count);
|
||||
}
|
||||
@ -225,7 +225,7 @@ namespace hgl
|
||||
* @param delete_count 要删除的数据项数量
|
||||
* @return 是否成功
|
||||
*/
|
||||
bool Delete(int start,int delete_count=1)
|
||||
bool Delete(int64 start,int64 delete_count=1)
|
||||
{
|
||||
if(!items)return(false);
|
||||
if(start>=count)return(false);
|
||||
@ -276,7 +276,7 @@ namespace hgl
|
||||
* @param start 要删除的数据项的索引值
|
||||
* @return 是否成功
|
||||
*/
|
||||
bool DeleteMove(int start,int delete_count=1)
|
||||
bool DeleteMove(int64 start,int64 delete_count=1)
|
||||
{
|
||||
if(!items)return(false);
|
||||
if(start>=count)return(false);
|
||||
@ -292,7 +292,7 @@ namespace hgl
|
||||
|
||||
if(delete_count<=0)return(false);
|
||||
|
||||
const int end_count=count-(start+delete_count);
|
||||
const int64 end_count=count-(start+delete_count);
|
||||
|
||||
if(end_count>0)
|
||||
hgl_cpy<T>(items+start,items+start+delete_count,end_count);
|
||||
@ -307,7 +307,7 @@ namespace hgl
|
||||
* @param a 第一个数据的位置
|
||||
* @param b 第二个数据的位置
|
||||
*/
|
||||
void Exchange(int a,int b)
|
||||
void Exchange(int64 a,int64 b)
|
||||
{
|
||||
hgl_swap(items[a],items[b]);
|
||||
}
|
||||
@ -318,7 +318,7 @@ namespace hgl
|
||||
* @param old_index 旧的位置
|
||||
* @param move_number 要移动的数据个数
|
||||
*/
|
||||
bool Move(int new_index,int old_index,int move_number=1)
|
||||
bool Move(int64 new_index,int64 old_index,int64 move_number=1)
|
||||
{
|
||||
if(!items)return(false);
|
||||
if(new_index==old_index)return(false);
|
||||
@ -333,7 +333,7 @@ namespace hgl
|
||||
if(move_number<=0)return(false);
|
||||
|
||||
//直接创建新缓冲区复制过去,放弃旧缓冲区
|
||||
const int new_alloc_count=power_to_2(count);
|
||||
const int64 new_alloc_count=power_to_2(count);
|
||||
T *new_items=hgl_align_malloc<T>(new_alloc_count);
|
||||
|
||||
bool result;
|
||||
@ -543,7 +543,7 @@ namespace hgl
|
||||
* @param find_count 要查找的最大数量
|
||||
* @return <0 未找到或其它错误
|
||||
*/
|
||||
const int Find(const T &data,const int start=0,int find_count=-1)const
|
||||
const int64 Find(const T &data,const int64 start=0,int64 find_count=-1)const
|
||||
{
|
||||
if(!items||count<=0||start<0||start>=count)return(-1);
|
||||
|
||||
@ -556,7 +556,7 @@ namespace hgl
|
||||
/**
|
||||
* 在指定位置插入数据
|
||||
*/
|
||||
bool Insert(int pos,const T *data,const int data_number)
|
||||
bool Insert(int64 pos,const T *data,const int64 data_number)
|
||||
{
|
||||
if(!data||data_number<=0)
|
||||
return(false);
|
||||
@ -566,7 +566,7 @@ namespace hgl
|
||||
|
||||
if(count+data_number>alloc_count)
|
||||
{
|
||||
int new_alloc_count=power_to_2(alloc_count+data_number);
|
||||
int64 new_alloc_count=power_to_2(alloc_count+data_number);
|
||||
|
||||
T *new_items=hgl_align_malloc<T>(new_alloc_count);
|
||||
|
||||
@ -591,7 +591,7 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Insert(int pos,const T &data)
|
||||
bool Insert(int64 pos,const T &data)
|
||||
{
|
||||
return Insert(pos,&data,1);
|
||||
}
|
||||
@ -602,14 +602,14 @@ namespace hgl
|
||||
void WithoutList(DataArray<T> &result_list,const DataArray<T> &without_list)
|
||||
{
|
||||
result_list.Clear();
|
||||
const int count=this->GetCount();
|
||||
const int64 count=this->GetCount();
|
||||
|
||||
if(count<=0)return;
|
||||
|
||||
result_list.Clear();
|
||||
result_list.PreAlloc(count);
|
||||
|
||||
int result=0;
|
||||
int64 result=0;
|
||||
|
||||
T *p=result_list.items;
|
||||
|
||||
@ -626,8 +626,8 @@ namespace hgl
|
||||
result_list.SetCount(result);
|
||||
}
|
||||
|
||||
//int Intersection (SortedSets<T> &result,const SortedSets<T> &sets); ///<取得与指定合集的交集
|
||||
//int Intersection (const SortedSets<T> &set); ///<取得与指定合集的交集数量
|
||||
//int64 Intersection (SortedSets<T> &result,const SortedSets<T> &sets); ///<取得与指定合集的交集
|
||||
//int64 Intersection (const SortedSets<T> &set); ///<取得与指定合集的交集数量
|
||||
|
||||
///**
|
||||
// * 取得与指定交集is的合集,但排斥cs合集中的数据
|
||||
@ -636,9 +636,9 @@ namespace hgl
|
||||
// * @param cs 求排斥的合集
|
||||
// * @return 结果数量
|
||||
// */
|
||||
//int Intersection (SortedSets<T> &result,const SortedSets<T> &is,const SortedSets<T> &cs);
|
||||
//int64 Intersection (SortedSets<T> &result,const SortedSets<T> &is,const SortedSets<T> &cs);
|
||||
|
||||
//int Difference (const SortedSets<T> &is); ///<求差集数量
|
||||
//int64 Difference (const SortedSets<T> &is); ///<求差集数量
|
||||
|
||||
///**
|
||||
// * 求当前合集与另一个数据集的交集
|
||||
@ -646,7 +646,7 @@ namespace hgl
|
||||
// * @param list 要计算交集的数据集
|
||||
// * @return 交集数量
|
||||
// */
|
||||
//int Intersection(SortedSets<T> &result,const SortedSets<T> &list)
|
||||
//int64 Intersection(SortedSets<T> &result,const SortedSets<T> &list)
|
||||
//{
|
||||
// if(data_list.GetCount()<=0)
|
||||
// return(0);
|
||||
@ -663,7 +663,7 @@ namespace hgl
|
||||
// return result.GetCount();
|
||||
//}
|
||||
|
||||
//int Intersection(const SortedSets<T> &list)
|
||||
//int64 Intersection(const SortedSets<T> &list)
|
||||
//{
|
||||
// if(data_list.GetCount()<=0)
|
||||
// return(0);
|
||||
@ -671,10 +671,10 @@ namespace hgl
|
||||
// if(list.GetCount()<=0)
|
||||
// return(0);
|
||||
|
||||
// int count=0;
|
||||
// int64 count=0;
|
||||
|
||||
// T *obj=data_list.GetData();
|
||||
// for(int i=0;i<data_list.GetCount();i++)
|
||||
// for(int64 i=0;i<data_list.GetCount();i++)
|
||||
// {
|
||||
// if(list.IsMember(*obj))
|
||||
// ++count;
|
||||
@ -685,7 +685,7 @@ namespace hgl
|
||||
// return count;
|
||||
//}
|
||||
|
||||
//int Intersection(SortedSets<T> &result,const SortedSets<T> &il,const SortedSets<T> &cl)
|
||||
//int64 Intersection(SortedSets<T> &result,const SortedSets<T> &il,const SortedSets<T> &cl)
|
||||
//{
|
||||
// if(data_list.GetCount()<=0)
|
||||
// return(0);
|
||||
@ -694,7 +694,7 @@ namespace hgl
|
||||
// return(0);
|
||||
|
||||
// T *obj=data_list.GetData();
|
||||
// for(int i=0;i<data_list.GetCount();i++)
|
||||
// for(int64 i=0;i<data_list.GetCount();i++)
|
||||
// {
|
||||
// if(il.IsMember(*obj))
|
||||
// if(!cl.IsMember(*obj))
|
||||
@ -705,7 +705,7 @@ namespace hgl
|
||||
// return result.GetCount();
|
||||
//}
|
||||
|
||||
//int Difference(const DataArray &is)
|
||||
//int64 Difference(const DataArray &is)
|
||||
//{
|
||||
// if(data_list.GetCount()<=0)
|
||||
// return(is.GetCount());
|
||||
@ -713,10 +713,10 @@ namespace hgl
|
||||
// if(is.GetCount()<=0)
|
||||
// return(data_list.GetCount());
|
||||
|
||||
// int count=0;
|
||||
// int64 count=0;
|
||||
|
||||
// T *obj=data_list.GetData();
|
||||
// for(int i=0;i<data_list.GetCount();i++)
|
||||
// for(int64 i=0;i<data_list.GetCount();i++)
|
||||
// {
|
||||
// if(!is.IsMember(*obj))
|
||||
// ++count;
|
||||
@ -727,6 +727,6 @@ namespace hgl
|
||||
// return count;
|
||||
//}
|
||||
|
||||
//int Clear (const SortedSets<T> &clear_sets); ///<清除指定合集中所有数据
|
||||
//int64 Clear (const SortedSets<T> &clear_sets); ///<清除指定合集中所有数据
|
||||
};//template<typename T> class DataArray
|
||||
}//namespace hgl
|
||||
|
@ -14,15 +14,15 @@ namespace hgl
|
||||
|
||||
DataArray<T> data_list;
|
||||
|
||||
bool FindPos(const T &flag,int &pos)const ///<查找数据如果插入后,会所在的位置,返回是否存在这个数据
|
||||
bool FindPos(const T &flag,int64 &pos)const ///<查找数据如果插入后,会所在的位置,返回是否存在这个数据
|
||||
{return FindInsertPositionInSortedArray(&pos,data_list,flag);}
|
||||
|
||||
int FindPos(const T &flag)const{int pos;return FindPos(flag,pos)?pos:-1;} ///<查找数据如果插入后,会所在的位置
|
||||
int64 FindPos(const T &flag)const{int64 pos;return FindPos(flag,pos)?pos:-1;} ///<查找数据如果插入后,会所在的位置
|
||||
|
||||
public: //属性
|
||||
|
||||
T * GetData ()const{return data_list.GetData();} ///<取得数据指针
|
||||
int GetCount ()const{return data_list.GetCount();} ///<取得数据总量
|
||||
int64 GetCount ()const{return data_list.GetCount();} ///<取得数据总量
|
||||
|
||||
const bool IsEmpty ()const{return data_list.IsEmpty();} ///<确认列表是否为空
|
||||
|
||||
@ -40,15 +40,15 @@ namespace hgl
|
||||
SortedSets()=default;
|
||||
virtual ~SortedSets()=default;
|
||||
|
||||
void SetCount (int count){data_list.SetCount(count);} ///<指定数据数量,一般用于批量加载前的处理
|
||||
void PreAlloc (int count){data_list.Alloc(count);} ///<预分配指定数量的数据空间
|
||||
void SetCount (int64 count){data_list.SetCount(count);} ///<指定数据数量,一般用于批量加载前的处理
|
||||
void PreAlloc (int64 count){data_list.Alloc(count);} ///<预分配指定数量的数据空间
|
||||
|
||||
/**
|
||||
* 查找数据是否存在
|
||||
* @param flag 数据
|
||||
* @return 数据所在索引,-1表示不存在
|
||||
*/
|
||||
int Find (const T &flag)const
|
||||
int64 Find (const T &flag)const
|
||||
{
|
||||
return FindDataPositionInSortedArray(data_list,flag);
|
||||
}
|
||||
@ -61,7 +61,7 @@ namespace hgl
|
||||
* @return 插入的位置
|
||||
* @reutrn -1 数据已存在,添加失败
|
||||
*/
|
||||
int Add (const T &data)
|
||||
int64 Add (const T &data)
|
||||
{
|
||||
if(data_list.GetCount()<=0)
|
||||
{
|
||||
@ -73,7 +73,7 @@ namespace hgl
|
||||
}
|
||||
else
|
||||
{
|
||||
int pos;
|
||||
int64 pos;
|
||||
|
||||
if(FindPos(data,pos))
|
||||
return(-1); //数据已存在
|
||||
@ -87,7 +87,7 @@ namespace hgl
|
||||
/*
|
||||
* 添加一批数据
|
||||
*/
|
||||
int Add (T *dl,const int count)
|
||||
int64 Add (T *dl,const int64 count)
|
||||
{
|
||||
if(!dl||count<=0)return -1;
|
||||
|
||||
@ -97,10 +97,10 @@ namespace hgl
|
||||
data_list.Alloc(data_list.GetCount()+count);
|
||||
|
||||
{
|
||||
int pos;
|
||||
int result=0;
|
||||
int64 pos;
|
||||
int64 result=0;
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
for(int64 i=0;i<count;i++)
|
||||
{
|
||||
if(FindPos(*dl,pos))
|
||||
break;
|
||||
@ -115,11 +115,11 @@ namespace hgl
|
||||
}
|
||||
}
|
||||
|
||||
bool DeleteAt (const int pos){return data_list.DeleteMove(pos,1);} ///<删除一个数据,使用序号
|
||||
bool DeleteAt (const int64 pos){return data_list.DeleteMove(pos,1);} ///<删除一个数据,使用序号
|
||||
|
||||
bool Delete (const T &data) ///<删除一个数据
|
||||
{
|
||||
int pos=Find(data);
|
||||
int64 pos=Find(data);
|
||||
|
||||
if(pos==-1)return(false);
|
||||
|
||||
@ -132,12 +132,12 @@ namespace hgl
|
||||
* @param count 数据个数
|
||||
* @return 成功删除的数据个数
|
||||
*/
|
||||
int Delete(T *dp,const int count)
|
||||
int64 Delete(T *dp,const int64 count)
|
||||
{
|
||||
int total=0;
|
||||
int pos;
|
||||
int64 total=0;
|
||||
int64 pos;
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
for(int64 i=0;i<count;i++)
|
||||
{
|
||||
pos=Find(*dp);
|
||||
if(pos!=-1)
|
||||
@ -155,7 +155,7 @@ namespace hgl
|
||||
void Free (){data_list.Free();} ///<清除数据,并释放内存
|
||||
void Clear (){data_list.Clear();} ///<清除数据,但不释放内存
|
||||
|
||||
bool Get (const int index,T &data) ///<根据序列号取得指定数据
|
||||
bool Get (const int64 index,T &data) ///<根据序列号取得指定数据
|
||||
{
|
||||
if(index<0||index>=data_list.GetCount())
|
||||
return(false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user