renamed to SortedSets instead of Sets.

This commit is contained in:
2022-02-08 11:10:20 +08:00
parent 3b55f2f42b
commit 3c047a6803
5 changed files with 41 additions and 40 deletions

View File

@@ -1,7 +1,7 @@
#ifndef HGL_IO_INPUT_EVENT_INCLUDE
#define HGL_IO_INPUT_EVENT_INCLUDE
#include<hgl/type/Sets.h>
#include<hgl/type/SortedSets.h>
#include<hgl/io/event/InputEventSource.h>
namespace hgl
{
@@ -31,7 +31,7 @@ namespace hgl
InputEventSource source_type;
Sets<InputEvent *> sub_event_proc[size_t(InputEventSource::RANGE_SIZE)];
SortedSets<InputEvent *> sub_event_proc[size_t(InputEventSource::RANGE_SIZE)];
public:

View File

@@ -2,7 +2,7 @@
#define HGL_THREAD_INCLUDE
#include<hgl/type/DataType.h>
#include<hgl/type/Sets.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/String.h>
#include<hgl/thread/ThreadMutex.h>
#include<hgl/log/LogInfo.h>
@@ -123,7 +123,7 @@ namespace hgl
{
protected:
Sets<THREAD *> thread_set;
SortedSets<THREAD *> thread_set;
public:

View File

@@ -5,7 +5,7 @@
#include<hgl/type/Queue.h>
#include<hgl/thread/RWLock.h>
#include<hgl/thread/ThreadMutex.h>
#include<hgl/type/Sets.h>
#include<hgl/type/SortedSets.h>
namespace hgl
{
/**

View File

@@ -1,7 +1,7 @@
#ifndef HGL_TYPE_SETS_CPP
#define HGL_TYPE_SETS_CPP
#ifndef HGL_TYPE_SORTED_SETS_CPP
#define HGL_TYPE_SORTED_SETS_CPP
#include<hgl/type/Sets.h>
#include<hgl/type/SortedSets.h>
namespace hgl
{
/**
@@ -10,7 +10,7 @@ namespace hgl
* @return -1
*/
template<typename T>
const int Sets<T>::Find(const T &flag)const
const int SortedSets<T>::Find(const T &flag)const
{
int left=0,right=data_list.GetCount()-1; //使用left,right而不使用min,max是为了让代码能够更好的阅读。
int mid;
@@ -42,7 +42,7 @@ namespace hgl
}
template<typename T>
bool Sets<T>::FindPos(const T &flag,int &pos)const
bool SortedSets<T>::FindPos(const T &flag,int &pos)const
{
int left=0,right=data_list.GetCount()-1;
int mid;
@@ -128,7 +128,7 @@ namespace hgl
* @return
*/
template<typename T>
int Sets<T>::Add(const T &data)
int SortedSets<T>::Add(const T &data)
{
if(data_list.GetCount()<=0)
{
@@ -156,7 +156,7 @@ namespace hgl
* @return
*/
template<typename T>
int Sets<T>::Add(const T *dp,const int count)
int SortedSets<T>::Add(const T *dp,const int count)
{
int total=0;
@@ -177,7 +177,7 @@ namespace hgl
* @return
*/
template<typename T>
bool Sets<T>::Update(const T &data)
bool SortedSets<T>::Update(const T &data)
{
if(data_list.GetCount()<=0)
return(false);
@@ -196,7 +196,7 @@ namespace hgl
* @param pos
*/
template<typename T>
bool Sets<T>::DeleteBySerial(int pos)
bool SortedSets<T>::DeleteBySerial(int pos)
{
if(pos<0||pos>=data_list.GetCount())return(false);
@@ -208,7 +208,7 @@ namespace hgl
* @param data
*/
template<typename T>
bool Sets<T>::Delete(const T &data)
bool SortedSets<T>::Delete(const T &data)
{
int pos=Find(data);
@@ -224,7 +224,7 @@ namespace hgl
* @return
*/
template<typename T>
int Sets<T>::Delete(T *dp,const int count)
int SortedSets<T>::Delete(T *dp,const int count)
{
int total=0;
int pos;
@@ -248,7 +248,7 @@ namespace hgl
*
*/
template<typename T>
void Sets<T>::Clear()
void SortedSets<T>::Clear()
{
data_list.Clear();
}
@@ -257,7 +257,7 @@ namespace hgl
*
*/
template<typename T>
void Sets<T>::ClearData()
void SortedSets<T>::ClearData()
{
data_list.ClearData();
}
@@ -266,7 +266,7 @@ namespace hgl
*
*/
template<typename T>
bool Sets<T>::Rand(T &result)const
bool SortedSets<T>::Rand(T &result)const
{
return data_list.Rand(result);
}
@@ -278,7 +278,7 @@ namespace hgl
* @return
*/
template<typename T>
int Sets<T>::Intersection(Sets<T> &result,const Sets<T> &list)
int SortedSets<T>::Intersection(SortedSets<T> &result,const SortedSets<T> &list)
{
if(data_list.GetCount()<=0)
return(0);
@@ -296,7 +296,7 @@ namespace hgl
}
template<typename T>
int Sets<T>::Intersection(const Sets<T> &list)
int SortedSets<T>::Intersection(const SortedSets<T> &list)
{
if(data_list.GetCount()<=0)
return(0);
@@ -319,7 +319,7 @@ namespace hgl
}
template<typename T>
int Sets<T>::Intersection(Sets<T> &result,const Sets<T> &il,const Sets<T> &cl)
int SortedSets<T>::Intersection(SortedSets<T> &result,const SortedSets<T> &il,const SortedSets<T> &cl)
{
if(data_list.GetCount()<=0)
return(0);
@@ -340,7 +340,7 @@ namespace hgl
}
template<typename T>
int Sets<T>::Difference(const Sets<T> &is)
int SortedSets<T>::Difference(const SortedSets<T> &is)
{
if(data_list.GetCount()<=0)
return(is.GetCount());
@@ -362,4 +362,4 @@ namespace hgl
return count;
}
}//namespace hgl
#endif//HGL_TYPE_SETS_CPP
#endif//HGL_TYPE_SORTED_SETS_CPP

View File

@@ -1,13 +1,14 @@
#ifndef HGL_TYPE_SETS_INCLUDE
#define HGL_TYPE_SETS_INCLUDE
#ifndef HGL_TYPE_SORTED_SETS_INCLUDE
#define HGL_TYPE_SORTED_SETS_INCLUDE
#include<hgl/type/List.h>
namespace hgl
{
/**
* 使
*/
template<typename T> class Sets
* </br>
*
*/
template<typename T> class SortedSets
{
protected:
@@ -27,8 +28,8 @@ namespace hgl
public:
Sets()=default;
virtual ~Sets()=default;
SortedSets()=default;
virtual ~SortedSets()=default;
void SetCount (int count){data_list.SetCount(count);} ///<指定数据数量,一般用于批量加载前的处理
void PreMalloc (int count){data_list.PreMalloc(count);} ///<预分配指定数量的数据空间
@@ -37,7 +38,7 @@ namespace hgl
const bool IsMember (const T &v)const{return(Find(v)!=-1);} ///<确认是否成员
int Add (const T &); ///<添加一个数据,返回索引号,返回-1表示数据已存在
int Add (const T *,const int); ///<添加一批数据
int Add (const Sets<T> &s){return Add(s.GetData(),s.GetCount());} ///<添加一批数据
int Add (const SortedSets<T> &s){return Add(s.GetData(),s.GetCount());} ///<添加一批数据
bool Update (const T &); ///<更新一个数据
bool Delete (const T &); ///<删除一个数据
int Delete (T *,const int); ///<删除一批数据
@@ -58,8 +59,8 @@ namespace hgl
bool GetBegin (T &data){return data_list.Begin(data);} ///<取得最前面一个数据
bool GetEnd (T &data){return data_list.End(data);} ///<取得最后面一个数据
int Intersection (Sets<T> &result,const Sets<T> &set); ///<取得与指定合集的交集
int Intersection (const Sets<T> &set); ///<取得与指定合集的交集数量
int Intersection (SortedSets<T> &result,const SortedSets<T> &set); ///<取得与指定合集的交集
int Intersection (const SortedSets<T> &set); ///<取得与指定合集的交集数量
/**
* is的合集cs合集中的数据
@@ -68,16 +69,16 @@ namespace hgl
* @param cs
* @return
*/
int Intersection (Sets<T> &result,const Sets<T> &is,const Sets<T> &cs);
int Intersection (SortedSets<T> &result,const SortedSets<T> &is,const SortedSets<T> &cs);
int Difference (const Sets<T> &is); ///<求差集数量
int Difference (const SortedSets<T> &is); ///<求差集数量
void operator =(const Sets<T> &set){data_list=set.data_list;} ///<等号操作符重载
void operator =(const SortedSets<T> &set){data_list=set.data_list;} ///<等号操作符重载
bool Rand (T &)const; ///<随机取得一个
virtual void Enum (void (*enum_func)(T &)){data_list.Enum(enum_func);} ///<枚举所有数据成员
};//template<typename T> class Sets
};//template<typename T> class SortedSets
}//namespace hgl
#include<hgl/type/Sets.cpp>
#endif//HGL_TYPE_SETS_INCLUDE
#include<hgl/type/SortedSets.cpp>
#endif//HGL_TYPE_SORTED_SETS_INCLUDE