use Contains instead of IsMember/IsExist

This commit is contained in:
hyzboy 2024-09-30 23:28:55 +08:00
parent 0a2ca9272e
commit d286de5b68
14 changed files with 35 additions and 31 deletions

View File

@ -145,10 +145,10 @@ namespace hgl
return indexOfCondition(&cee);
}
virtual bool isMember(const void *value) const{return indexOf(value)!=-1;} ///<判断当前数据是否是其成员
virtual bool Contains(const void *value) const{return indexOf(value)!=-1;} ///<判断当前数据是否是其成员
template<typename T>
bool isMemberValue(const T &value)const{return indexOf<T>(value)!=-1;} ///<判断当前数据是否是其成员
bool ContainsValue(const T &value)const{return indexOf<T>(value)!=-1;} ///<判断当前数据是否是其成员
virtual int64 RemoveCondition(CheckElement *condition,int max_count=1); ///<按条件移除

View File

@ -91,7 +91,7 @@ namespace hgl
public:
const bool IsMember(const SC *str,int length)const ///<判断字符串是否为合集成员
const bool Contains(const SC *str,int length)const ///<判断字符串是否为合集成员
{
if(!str||!*str||length<=0)return(-1);
@ -154,7 +154,11 @@ namespace hgl
csv.id=GetID(str,length);
if(csv.id>=0)
{
str_list.Get(csv.id,csv);
return csv.id;
}
csv.str_data=&str_data;
csv.id =str_set.GetCount();

View File

@ -615,7 +615,7 @@ namespace hgl
for(const T *sp:*this)
{
if(!without_list.IsExist(*sp))
if(!without_list.Contains(*sp))
{
*p=*sp;
++p;
@ -656,7 +656,7 @@ namespace hgl
// data_list.Enum([&](T &obj)
// {
// if(list->IsMember(obj))
// if(list->Contains(obj))
// result.Add(obj);
// });
@ -676,7 +676,7 @@ namespace hgl
// T *obj=data_list.GetData();
// for(int64 i=0;i<data_list.GetCount();i++)
// {
// if(list.IsMember(*obj))
// if(list.Contains(*obj))
// ++count;
// ++obj;
@ -696,8 +696,8 @@ namespace hgl
// T *obj=data_list.GetData();
// for(int64 i=0;i<data_list.GetCount();i++)
// {
// if(il.IsMember(*obj))
// if(!cl.IsMember(*obj))
// if(il.Contains(*obj))
// if(!cl.Contains(*obj))
// result.Add(*obj);
// ++obj;
// }
@ -718,7 +718,7 @@ namespace hgl
// T *obj=data_list.GetData();
// for(int64 i=0;i<data_list.GetCount();i++)
// {
// if(!is.IsMember(*obj))
// if(!is.Contains(*obj))
// ++count;
// ++obj;

View File

@ -119,7 +119,7 @@ namespace hgl
virtual void Clear(){data_array.Clear();} ///<清除所有数据,但不清空缓冲区
virtual int Find(const T &data)const{return data_array.Find(data);} ///<查找指定数据的索引
virtual bool IsExist(const T &flag)const{return Find(flag)>=0;} ///<确认数据项是否存在
virtual bool Contains(const T &flag)const{return Find(flag)>=0;} ///<确认数据项是否存在
virtual bool Delete(int start,int num=1){return data_array.Delete(start,num);} ///<删除指定索引的数据
virtual bool DeleteMove(int start,int num=1){return data_array.DeleteMove(start,num);} ///<删除指定索引的数据,将后面紧邻的数据前移

View File

@ -618,7 +618,7 @@ namespace hgl
for(int i=0;i<count;i++)
{
if(in_list.IsExist(*sp))
if(in_list.Contains(*sp))
with_list.Add(*sp);
++sp;
@ -642,7 +642,7 @@ namespace hgl
for(int i=0;i<count;i++)
{
if(!in_list.IsExist(*sp))
if(!in_list.Contains(*sp))
without_list.Add(*sp);
++sp;

View File

@ -47,8 +47,8 @@ namespace hgl
int FindPos(const K &flag)const{int pos;FindPos(flag,pos);return(pos);} ///<查找数据如果插入后,会所在的位置
int Find(const K &)const; ///<查找数据是否存在,返回-1表示数据不存在
int FindByValue(const V &)const; ///<查找数据是否存在,返回-1表示数据不存在
bool KeyExist(const K &key)const{return(Find(key)!=-1);} ///<确认这个数据是否存在
bool ValueExist(const V &value)const{return(FindByValue(value)!=-1);} ///<确认这个数据是否存在
bool ContainsKey(const K &key)const{return(Find(key)!=-1);} ///<确认这个数据是否存在
bool ContainsValue(const V &value)const{return(FindByValue(value)!=-1);} ///<确认这个数据是否存在
bool Check(const K &key,const V &value)const; ///<确认数据是否是这个
virtual V * GetPointer(const K &key)const; ///<取得数据指针
virtual int GetValueAndSerial(const K &,V &) const; ///<取得数据与索引

View File

@ -44,7 +44,7 @@ namespace hgl
List<T *>::Clear();
}
virtual bool IsExist(const ItemPointer &flag)const override ///<确认数据项是否存在
virtual bool Contains(const ItemPointer &flag)const override ///<确认数据项是否存在
{
return List<T *>::Find((T *)flag)!=-1;
}

View File

@ -90,7 +90,7 @@ namespace hgl
{
if(!obj)return(false);
if(items.KeyExist(key))
if(items.ContainsKey(key))
return(false);
items.Add(key,obj);
@ -125,7 +125,7 @@ namespace hgl
return(nullptr);
}
virtual bool ValueExist(V *value) ///<确认这个对象是否存在
virtual bool ContainsValue(V *value) ///<确认这个对象是否存在
{
return(items.FindByValue(value)!=-1);
}

View File

@ -40,8 +40,8 @@ namespace hgl
DataArray<T> & GetActiveArray(){return Active.GetArray();} ///<取得所有活跃数据
bool IsActive (const T &data)const{return Active.IsExist(data);} ///<是否为活跃的
bool IsIdle (const T &data)const{return Idle.IsExist(data);} ///<是否为非活跃的
bool IsActive (const T &data)const{return Active.Contains(data);} ///<是否为活跃的
bool IsIdle (const T &data)const{return Idle.Contains(data);} ///<是否为非活跃的
bool IsFull()const ///<活跃队列是否已满
{

View File

@ -54,7 +54,7 @@ namespace hgl
const bool IsEmpty ()const{return GetCount()==0;} ///<确认列表是否为空
const bool IsExist (const T &data)const
const bool Contains (const T &data)const
{
if(data_array[read_index].Find(data,read_offset)!=-1)
return(true);

View File

@ -57,10 +57,10 @@ namespace hgl
const K *kp=key_list;
for(int i=0;i<key_count;i++)
{
if(active_items.KeyExist(*kp))
if(active_items.ContainsKey(*kp))
++(stats.active);
else
if(idle_items.KeyExist(*kp))
if(idle_items.ContainsKey(*kp))
++(stats.idle);
else
++(stats.not_found);
@ -74,22 +74,22 @@ namespace hgl
/**
* key是否在活跃列表
*/
bool KeyExistActive(const K &key)const{return active_items.KeyExist(key);}
bool KeyExistActive(const K &key)const{return active_items.ContainsKey(key);}
/**
* key是否在闲置列表
*/
bool KeyExistIdle(const K &key)const{return idle_items.KeyExist(key);}
bool KeyExistIdle(const K &key)const{return idle_items.ContainsKey(key);}
/**
* key是否在列表中()
*/
bool KeyExist(const K &key)const
bool ContainsKey(const K &key)const
{
if(active_items.KeyExist(key))
if(active_items.ContainsKey(key))
return(true);
if(idle_items.KeyExist(key))
if(idle_items.ContainsKey(key))
return(true);
return(false);
@ -109,7 +109,7 @@ namespace hgl
if(active_items.Get(key,ai)) //在活跃列表中找
return ai->ref_count;
if(idle_items.KeyExist(key))
if(idle_items.ContainsKey(key))
return 0;
return -1;

View File

@ -54,7 +54,7 @@ namespace hgl
return FindDataPositionInSortedArray(data_list,flag);
}
bool IsMember (const T &v)const{return(Find(v)!=-1);} ///<确认是否成员
bool Contains (const T &v)const{return(Find(v)!=-1);} ///<确认是否成员
/**
*

View File

@ -18,7 +18,7 @@ namespace hgl
OnlyWriteLock owl(log_list);
if(log_list->IsExist(log)) //重复添加
if(log_list->Contains(log)) //重复添加
return(false);
log_list->Add(log);

View File

@ -119,7 +119,7 @@ namespace hgl
if(!ud)
return(false);
if(!ud_set.IsMember(ud))
if(!ud_set.Contains(ud))
return(false);
const int ud_end=ud->GetEnd();