renamed to SortedSets instead of Sets.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#ifndef HGL_IO_INPUT_EVENT_INCLUDE
|
#ifndef HGL_IO_INPUT_EVENT_INCLUDE
|
||||||
#define 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>
|
#include<hgl/io/event/InputEventSource.h>
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
@@ -31,7 +31,7 @@ namespace hgl
|
|||||||
|
|
||||||
InputEventSource source_type;
|
InputEventSource source_type;
|
||||||
|
|
||||||
Sets<InputEvent *> sub_event_proc[size_t(InputEventSource::RANGE_SIZE)];
|
SortedSets<InputEvent *> sub_event_proc[size_t(InputEventSource::RANGE_SIZE)];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
#define HGL_THREAD_INCLUDE
|
#define HGL_THREAD_INCLUDE
|
||||||
|
|
||||||
#include<hgl/type/DataType.h>
|
#include<hgl/type/DataType.h>
|
||||||
#include<hgl/type/Sets.h>
|
#include<hgl/type/SortedSets.h>
|
||||||
#include<hgl/type/String.h>
|
#include<hgl/type/String.h>
|
||||||
#include<hgl/thread/ThreadMutex.h>
|
#include<hgl/thread/ThreadMutex.h>
|
||||||
#include<hgl/log/LogInfo.h>
|
#include<hgl/log/LogInfo.h>
|
||||||
@@ -123,7 +123,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Sets<THREAD *> thread_set;
|
SortedSets<THREAD *> thread_set;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
#include<hgl/type/Queue.h>
|
#include<hgl/type/Queue.h>
|
||||||
#include<hgl/thread/RWLock.h>
|
#include<hgl/thread/RWLock.h>
|
||||||
#include<hgl/thread/ThreadMutex.h>
|
#include<hgl/thread/ThreadMutex.h>
|
||||||
#include<hgl/type/Sets.h>
|
#include<hgl/type/SortedSets.h>
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
#ifndef HGL_TYPE_SETS_CPP
|
#ifndef HGL_TYPE_SORTED_SETS_CPP
|
||||||
#define HGL_TYPE_SETS_CPP
|
#define HGL_TYPE_SORTED_SETS_CPP
|
||||||
|
|
||||||
#include<hgl/type/Sets.h>
|
#include<hgl/type/SortedSets.h>
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -10,7 +10,7 @@ namespace hgl
|
|||||||
* @return 数据所在索引,-1表示不存在
|
* @return 数据所在索引,-1表示不存在
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
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 left=0,right=data_list.GetCount()-1; //使用left,right而不使用min,max是为了让代码能够更好的阅读。
|
||||||
int mid;
|
int mid;
|
||||||
@@ -42,7 +42,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
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 left=0,right=data_list.GetCount()-1;
|
||||||
int mid;
|
int mid;
|
||||||
@@ -128,7 +128,7 @@ namespace hgl
|
|||||||
* @return 位置
|
* @return 位置
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int Sets<T>::Add(const T &data)
|
int SortedSets<T>::Add(const T &data)
|
||||||
{
|
{
|
||||||
if(data_list.GetCount()<=0)
|
if(data_list.GetCount()<=0)
|
||||||
{
|
{
|
||||||
@@ -156,7 +156,7 @@ namespace hgl
|
|||||||
* @return 成功加入的数据个数
|
* @return 成功加入的数据个数
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
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;
|
int total=0;
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ namespace hgl
|
|||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool Sets<T>::Update(const T &data)
|
bool SortedSets<T>::Update(const T &data)
|
||||||
{
|
{
|
||||||
if(data_list.GetCount()<=0)
|
if(data_list.GetCount()<=0)
|
||||||
return(false);
|
return(false);
|
||||||
@@ -196,7 +196,7 @@ namespace hgl
|
|||||||
* @param pos 索引编号
|
* @param pos 索引编号
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool Sets<T>::DeleteBySerial(int pos)
|
bool SortedSets<T>::DeleteBySerial(int pos)
|
||||||
{
|
{
|
||||||
if(pos<0||pos>=data_list.GetCount())return(false);
|
if(pos<0||pos>=data_list.GetCount())return(false);
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ namespace hgl
|
|||||||
* @param data 数据
|
* @param data 数据
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool Sets<T>::Delete(const T &data)
|
bool SortedSets<T>::Delete(const T &data)
|
||||||
{
|
{
|
||||||
int pos=Find(data);
|
int pos=Find(data);
|
||||||
|
|
||||||
@@ -224,7 +224,7 @@ namespace hgl
|
|||||||
* @return 成功删除的数据个数
|
* @return 成功删除的数据个数
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
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 total=0;
|
||||||
int pos;
|
int pos;
|
||||||
@@ -248,7 +248,7 @@ namespace hgl
|
|||||||
* 清除所有数据
|
* 清除所有数据
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Sets<T>::Clear()
|
void SortedSets<T>::Clear()
|
||||||
{
|
{
|
||||||
data_list.Clear();
|
data_list.Clear();
|
||||||
}
|
}
|
||||||
@@ -257,7 +257,7 @@ namespace hgl
|
|||||||
* 清除所有数据,但不释放内存
|
* 清除所有数据,但不释放内存
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Sets<T>::ClearData()
|
void SortedSets<T>::ClearData()
|
||||||
{
|
{
|
||||||
data_list.ClearData();
|
data_list.ClearData();
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ namespace hgl
|
|||||||
* 随机取得一个数据
|
* 随机取得一个数据
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool Sets<T>::Rand(T &result)const
|
bool SortedSets<T>::Rand(T &result)const
|
||||||
{
|
{
|
||||||
return data_list.Rand(result);
|
return data_list.Rand(result);
|
||||||
}
|
}
|
||||||
@@ -278,7 +278,7 @@ namespace hgl
|
|||||||
* @return 交集数量
|
* @return 交集数量
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
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)
|
if(data_list.GetCount()<=0)
|
||||||
return(0);
|
return(0);
|
||||||
@@ -296,7 +296,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int Sets<T>::Intersection(const Sets<T> &list)
|
int SortedSets<T>::Intersection(const SortedSets<T> &list)
|
||||||
{
|
{
|
||||||
if(data_list.GetCount()<=0)
|
if(data_list.GetCount()<=0)
|
||||||
return(0);
|
return(0);
|
||||||
@@ -319,7 +319,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
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)
|
if(data_list.GetCount()<=0)
|
||||||
return(0);
|
return(0);
|
||||||
@@ -340,7 +340,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int Sets<T>::Difference(const Sets<T> &is)
|
int SortedSets<T>::Difference(const SortedSets<T> &is)
|
||||||
{
|
{
|
||||||
if(data_list.GetCount()<=0)
|
if(data_list.GetCount()<=0)
|
||||||
return(is.GetCount());
|
return(is.GetCount());
|
||||||
@@ -362,4 +362,4 @@ namespace hgl
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_TYPE_SETS_CPP
|
#endif//HGL_TYPE_SORTED_SETS_CPP
|
@@ -1,13 +1,14 @@
|
|||||||
#ifndef HGL_TYPE_SETS_INCLUDE
|
#ifndef HGL_TYPE_SORTED_SETS_INCLUDE
|
||||||
#define HGL_TYPE_SETS_INCLUDE
|
#define HGL_TYPE_SORTED_SETS_INCLUDE
|
||||||
|
|
||||||
#include<hgl/type/List.h>
|
#include<hgl/type/List.h>
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 集合数据列表中不允许数据出现重复性,同时它会将数据排序,所以也可以当做有序列表使用
|
* 有序合集</br>
|
||||||
*/
|
* 集合数据列表中不允许数据出现重复性,同时它会将数据排序
|
||||||
template<typename T> class Sets
|
*/
|
||||||
|
template<typename T> class SortedSets
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@@ -27,8 +28,8 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Sets()=default;
|
SortedSets()=default;
|
||||||
virtual ~Sets()=default;
|
virtual ~SortedSets()=default;
|
||||||
|
|
||||||
void SetCount (int count){data_list.SetCount(count);} ///<指定数据数量,一般用于批量加载前的处理
|
void SetCount (int count){data_list.SetCount(count);} ///<指定数据数量,一般用于批量加载前的处理
|
||||||
void PreMalloc (int count){data_list.PreMalloc(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);} ///<确认是否成员
|
const bool IsMember (const T &v)const{return(Find(v)!=-1);} ///<确认是否成员
|
||||||
int Add (const T &); ///<添加一个数据,返回索引号,返回-1表示数据已存在
|
int Add (const T &); ///<添加一个数据,返回索引号,返回-1表示数据已存在
|
||||||
int Add (const T *,const int); ///<添加一批数据
|
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 Update (const T &); ///<更新一个数据
|
||||||
bool Delete (const T &); ///<删除一个数据
|
bool Delete (const T &); ///<删除一个数据
|
||||||
int Delete (T *,const int); ///<删除一批数据
|
int Delete (T *,const int); ///<删除一批数据
|
||||||
@@ -58,8 +59,8 @@ namespace hgl
|
|||||||
bool GetBegin (T &data){return data_list.Begin(data);} ///<取得最前面一个数据
|
bool GetBegin (T &data){return data_list.Begin(data);} ///<取得最前面一个数据
|
||||||
bool GetEnd (T &data){return data_list.End(data);} ///<取得最后面一个数据
|
bool GetEnd (T &data){return data_list.End(data);} ///<取得最后面一个数据
|
||||||
|
|
||||||
int Intersection (Sets<T> &result,const Sets<T> &set); ///<取得与指定合集的交集
|
int Intersection (SortedSets<T> &result,const SortedSets<T> &set); ///<取得与指定合集的交集
|
||||||
int Intersection (const Sets<T> &set); ///<取得与指定合集的交集数量
|
int Intersection (const SortedSets<T> &set); ///<取得与指定合集的交集数量
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取得与指定交集is的合集,但排斥cs合集中的数据
|
* 取得与指定交集is的合集,但排斥cs合集中的数据
|
||||||
@@ -68,16 +69,16 @@ namespace hgl
|
|||||||
* @param cs 求排斥的合集
|
* @param cs 求排斥的合集
|
||||||
* @return 结果数量
|
* @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; ///<随机取得一个
|
bool Rand (T &)const; ///<随机取得一个
|
||||||
|
|
||||||
virtual void Enum (void (*enum_func)(T &)){data_list.Enum(enum_func);} ///<枚举所有数据成员
|
virtual void Enum (void (*enum_func)(T &)){data_list.Enum(enum_func);} ///<枚举所有数据成员
|
||||||
};//template<typename T> class Sets
|
};//template<typename T> class SortedSets
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#include<hgl/type/Sets.cpp>
|
#include<hgl/type/SortedSets.cpp>
|
||||||
#endif//HGL_TYPE_SETS_INCLUDE
|
#endif//HGL_TYPE_SORTED_SETS_INCLUDE
|
Reference in New Issue
Block a user