From a7b0cb6112c1dfad65523e619d88917398ca7c9a Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 23 Apr 2025 00:21:59 +0800 Subject: [PATCH] =?UTF-8?q?List=E6=A8=A1=E6=9D=BF=E6=94=B9=E5=90=8D?= =?UTF-8?q?=E4=B8=BAArrayList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/filesystem/EnumVolume.h | 2 +- inc/hgl/filesystem/FileSystem.h | 2 +- inc/hgl/text/FontInfo.h | 2 +- inc/hgl/thread/DataPost.h | 2 +- inc/hgl/thread/SwapColl.h | 4 +-- inc/hgl/thread/Workflow.h | 4 +-- inc/hgl/type/AccumMemoryManager.h | 2 +- inc/hgl/type/ConstStringSet.h | 4 +-- inc/hgl/type/Gradient.h | 2 +- inc/hgl/type/List.h | 24 ++++++++------- inc/hgl/type/Map.cpp | 4 +-- inc/hgl/type/Map.h | 6 ++-- inc/hgl/type/ObjectList.h | 34 ++++++++++----------- inc/hgl/type/Pool.h | 4 +-- inc/hgl/type/StringList.h | 2 +- src/FileSystem/EnumFile.cpp | 6 ++-- src/Log/Loginfo.cpp | 2 +- src/Text/ConstStringSetSaveToTextStream.cpp | 2 +- 18 files changed, 55 insertions(+), 53 deletions(-) diff --git a/inc/hgl/filesystem/EnumVolume.h b/inc/hgl/filesystem/EnumVolume.h index 92f37e3..0361303 100644 --- a/inc/hgl/filesystem/EnumVolume.h +++ b/inc/hgl/filesystem/EnumVolume.h @@ -77,7 +77,7 @@ namespace hgl } }; - using VolumeInfoList=List; + using VolumeInfoList=ArrayList; /** * 枚举当前计算机所有卷 diff --git a/inc/hgl/filesystem/FileSystem.h b/inc/hgl/filesystem/FileSystem.h index ada898d..29d467c 100644 --- a/inc/hgl/filesystem/FileSystem.h +++ b/inc/hgl/filesystem/FileSystem.h @@ -111,7 +111,7 @@ namespace hgl bool GetFileInfo(const os_char *filename,struct FileInfo &); ///<取得文件信息 - int GetFileInfoList(List &, const OSString &folder_name, bool proc_folder, bool proc_file, bool sub_folder); + int GetFileInfoList(ArrayList &, const OSString &folder_name, bool proc_folder, bool proc_file, bool sub_folder); }//namespace filesystem }//namespace hgl #endif//HGL_FILE_SYSTEM_INCLUDE diff --git a/inc/hgl/text/FontInfo.h b/inc/hgl/text/FontInfo.h index 8db20d6..423a2fb 100644 --- a/inc/hgl/text/FontInfo.h +++ b/inc/hgl/text/FontInfo.h @@ -50,7 +50,7 @@ namespace hgl } }; - using FontInfoList=List; + using FontInfoList=ArrayList; void EnumOSFonts(FontInfoList *); }//namespace hgl diff --git a/inc/hgl/thread/DataPost.h b/inc/hgl/thread/DataPost.h index 6cc0025..dc6e993 100644 --- a/inc/hgl/thread/DataPost.h +++ b/inc/hgl/thread/DataPost.h @@ -15,7 +15,7 @@ namespace hgl { protected: - List data_list[2]; + ArrayList data_list[2]; int post_index,recv_index; int recv_offset; diff --git a/inc/hgl/thread/SwapColl.h b/inc/hgl/thread/SwapColl.h index 4d72e99..c43ad27 100644 --- a/inc/hgl/thread/SwapColl.h +++ b/inc/hgl/thread/SwapColl.h @@ -64,7 +64,7 @@ namespace hgl operator S &(){return proc_list;} };//template class SwapColl - template using SwapList=SwapColl; ///<安全交换列表 + template using SwapList=SwapColl; ///<安全交换列表 template using SwapSet=SwapColl; ///<安全交换集合 /** @@ -150,7 +150,7 @@ namespace hgl operator S &(){return proc_list;} };//template class SemSwapColl - template using SemSwapList=SemSwapColl; ///<安全信号交换列表 + template using SemSwapList=SemSwapColl; ///<安全信号交换列表 template using SemSwapSet=SemSwapColl; ///<安全信号交换集合 }//namespace hgl #endif//HGL_THREAD_SWAP_LIST_INCLUDE diff --git a/inc/hgl/thread/Workflow.h b/inc/hgl/thread/Workflow.h index 8edd01c..83187c4 100644 --- a/inc/hgl/thread/Workflow.h +++ b/inc/hgl/thread/Workflow.h @@ -54,7 +54,7 @@ namespace hgl { public: - using WorkList=List; + using WorkList=ArrayList; private: @@ -214,7 +214,7 @@ namespace hgl { protected: - using WorkList=List; + using WorkList=ArrayList; WorkProc *work_proc; diff --git a/inc/hgl/type/AccumMemoryManager.h b/inc/hgl/type/AccumMemoryManager.h index dc66e5b..84ab37e 100644 --- a/inc/hgl/type/AccumMemoryManager.h +++ b/inc/hgl/type/AccumMemoryManager.h @@ -21,7 +21,7 @@ namespace hgl private: - List block_list; ///<数据块列表 + ArrayList block_list; ///<数据块列表 DataArray data_array; ///<数据 public: diff --git a/inc/hgl/type/ConstStringSet.h b/inc/hgl/type/ConstStringSet.h index 4e91826..c5f3596 100644 --- a/inc/hgl/type/ConstStringSet.h +++ b/inc/hgl/type/ConstStringSet.h @@ -72,7 +72,7 @@ namespace hgl SortedSet> str_set; ///<字符串集合 - List> str_list; ///<字符串列表 + ArrayList> str_list; ///<字符串列表 Map str_offset_map; ///<字符串映射 public: @@ -83,7 +83,7 @@ namespace hgl const DataArray &GetStringData()const{return str_data;} ///<取得字符串数据 - const List> &GetConstStringList()const{return str_list;} ///<取得字符串列表 + const ArrayList> &GetConstStringList()const{return str_list;} ///<取得字符串列表 public: diff --git a/inc/hgl/type/Gradient.h b/inc/hgl/type/Gradient.h index e999ed1..467890c 100644 --- a/inc/hgl/type/Gradient.h +++ b/inc/hgl/type/Gradient.h @@ -19,7 +19,7 @@ namespace hgl { using GS=GradientStop; - List stop_list; + ArrayList stop_list; bool dirty; diff --git a/inc/hgl/type/List.h b/inc/hgl/type/List.h index ad589b6..fcde68d 100644 --- a/inc/hgl/type/List.h +++ b/inc/hgl/type/List.h @@ -7,9 +7,11 @@ namespace hgl { /** - * List类用于保存数据列表。可以在列表中添加、删除、查找、访问和排序数据。 + * ArrayList类用于保存数据列表。可以在列表中添加、删除、查找、访问和排序数据。
+ * ArrayList使用真实的数组保存数据,没有独立的索引,所以仅适用于不会变动的小数据的保存与访问。
+ * 如果使用大块的数据,仅需要频繁的增删排序,建议使用IndexedList. */ - template class List ///列表处理类 + template class ArrayList ///阵列列表处理类 { protected: @@ -41,12 +43,12 @@ namespace hgl public: //方法 - List()=default; ///<本类构造函数 - List(const T *lt,const int n){Add(lt,n);} ///<本类构造函数 - List(const List <){operator=(lt);} ///<本类构造函数 - List(const std::initializer_list <){operator=(lt);} + ArrayList()=default; ///<本类构造函数 + ArrayList(const T *lt,const int n){Add(lt,n);} ///<本类构造函数 + ArrayList(const ArrayList <){operator=(lt);} ///<本类构造函数 + ArrayList(const std::initializer_list <){operator=(lt);} - virtual ~List(){Free();} ///<本类析构函数 + virtual ~ArrayList(){Free();} ///<本类析构函数 /** * 向列表中添加一个空数据 @@ -114,7 +116,7 @@ namespace hgl return(ec); } - int Add(const List &l){return Add(l.items,l.count);} ///<增加一批数据 + int Add(const ArrayList &l){return Add(l.items,l.count);} ///<增加一批数据 virtual void Free(){data_array.Free();} ///<清除所有数据,并释放内存 virtual void Clear(){data_array.Clear();} ///<清除所有数据,但不清空缓冲区 @@ -201,9 +203,9 @@ namespace hgl virtual bool GetFirst (T &data)const{return data_array.ReadAt(data,0);} ///<取第一个数据 virtual bool GetLast (T &data)const{return data_array.ReadAt(data,GetCount()-1);} ///<取最后一个数据 - };//template class List + };//template class ArrayList - template T *GetObjectFromList(const List &list,const int index) + template T *GetObjectFromList(const ArrayList &list,const int index) { T *obj; @@ -213,5 +215,5 @@ namespace hgl return(nullptr); } - using CharPointerList=hgl::List; + using CharPointerList=hgl::ArrayList; }//namespace hgl diff --git a/inc/hgl/type/Map.cpp b/inc/hgl/type/Map.cpp index b0912a2..bdd428b 100644 --- a/inc/hgl/type/Map.cpp +++ b/inc/hgl/type/Map.cpp @@ -605,7 +605,7 @@ namespace hgl * 统计出所有在in_list中出现的数据,产生的结果写入with_list */ template - void MapTemplate::WithList(MapTemplate::KVDataList &with_list,const List &in_list) + void MapTemplate::WithList(MapTemplate::KVDataList &with_list,const ArrayList &in_list) { with_list.Clear(); const int count=this->GetCount(); @@ -629,7 +629,7 @@ namespace hgl * 统计出所有没有出现在in_list中的数据,产生的结果写入without_list */ template - void MapTemplate::WithoutList(MapTemplate::KVDataList &without_list,const List &in_list) + void MapTemplate::WithoutList(MapTemplate::KVDataList &without_list,const ArrayList &in_list) { without_list.Clear(); const int count=this->GetCount(); diff --git a/inc/hgl/type/Map.h b/inc/hgl/type/Map.h index 357b75b..61b31e1 100644 --- a/inc/hgl/type/Map.h +++ b/inc/hgl/type/Map.h @@ -18,7 +18,7 @@ namespace hgl using ThisClass=MapTemplate; using KVDataPool=ObjectPool; - using KVDataList=List; + using KVDataList=ArrayList; KVDataPool data_pool; KVDataList data_list; @@ -134,8 +134,8 @@ namespace hgl void EnumAllValue(void (*enum_func)(V &)); ///<枚举所有数值 void EnumValue(bool (*enum_func)(V &)); ///<枚举所有数值(返回true/false表示是否继续) - void WithList(KVDataList &with_list,const List &in_list); ///<统计出所有在in_list中出现的数据,产生的结果写入with_list - void WithoutList(KVDataList &without_list,const List &in_list); ///<统计出所有没有出现在in_list中的数据,产生的结果写入without_list + void WithList(KVDataList &with_list,const ArrayList &in_list); ///<统计出所有在in_list中出现的数据,产生的结果写入with_list + void WithoutList(KVDataList &without_list,const ArrayList &in_list); ///<统计出所有没有出现在in_list中的数据,产生的结果写入without_list };//class MapTemplate template class Map:public MapTemplate > diff --git a/inc/hgl/type/ObjectList.h b/inc/hgl/type/ObjectList.h index f1a300d..99f5f2c 100644 --- a/inc/hgl/type/ObjectList.h +++ b/inc/hgl/type/ObjectList.h @@ -8,7 +8,7 @@ namespace hgl /** * 对象列表处理类与标准列表处理类的区别在于它对数据清除时会调用delete */ - template class ObjectListTemplate:public List ///对象列表处理类 + template class ObjectListTemplate:public ArrayList ///对象列表处理类 { protected: @@ -20,7 +20,7 @@ namespace hgl public: //方法 - ObjectListTemplate(ObjectLifecycleManager *_dlm):List(){dlm=_dlm;} + ObjectListTemplate(ObjectLifecycleManager *_dlm):ArrayList(){dlm=_dlm;} virtual ~ObjectListTemplate(){Free();} public: @@ -30,39 +30,39 @@ namespace hgl */ bool Insert(int index,const ItemPointer &obj) override { - return List::Insert(index,obj); + return ArrayList::Insert(index,obj); } virtual void Free() override ///<清除所有数据 { Clear(); - List::Free(); + ArrayList::Free(); } virtual void Clear() override ///<清除所有数据,但不清空缓冲区 { dlm->Clear(this->data_array.GetData(),this->data_array.GetCount()); - List::Clear(); + ArrayList::Clear(); } virtual bool Contains(const ItemPointer &flag)const override ///<确认数据项是否存在 { - return List::Find((T *)flag)!=-1; + return ArrayList::Find((T *)flag)!=-1; } - virtual bool Unlink(int index){return List::Delete(index);} ///<将指定索引处的数据与列表断开 - virtual bool UnlinkMove(int index){return List::DeleteShift(index);} ///<将指定索引处的数据与列表断开,将前移后面的数据 - virtual bool Unlink(int start,int number){return List::Delete(start,number);} ///<将指定索引处的数据与列表断开 - virtual bool UnlinkByValue(ItemPointer &ip){return List::DeleteByValue(ip);} ///<将一个指定数据与列表断开 - virtual void UnlinkByValue(ItemPointer *ip,int n){List::DeleteByValue(ip,n);} ///<将一批指定数据与列表断开 - virtual void UnlinkAll(){List::Clear();} ///<断开所有数据 + virtual bool Unlink(int index){return ArrayList::Delete(index);} ///<将指定索引处的数据与列表断开 + virtual bool UnlinkMove(int index){return ArrayList::DeleteShift(index);} ///<将指定索引处的数据与列表断开,将前移后面的数据 + virtual bool Unlink(int start,int number){return ArrayList::Delete(start,number);} ///<将指定索引处的数据与列表断开 + virtual bool UnlinkByValue(ItemPointer &ip){return ArrayList::DeleteByValue(ip);} ///<将一个指定数据与列表断开 + virtual void UnlinkByValue(ItemPointer *ip,int n){ArrayList::DeleteByValue(ip,n);} ///<将一批指定数据与列表断开 + virtual void UnlinkAll(){ArrayList::Clear();} ///<断开所有数据 private: bool _Delete(int index,int num) { - if(index<0||num<=0||index+num>=List::GetCount()) + if(index<0||num<=0||index+num>=ArrayList::GetCount()) return(false); dlm->Clear(this->data_array.GetData()+index,num); @@ -85,7 +85,7 @@ namespace hgl if(!_Delete(index,num)) return(false); - return List::Delete(index,num); + return ArrayList::Delete(index,num); } /** @@ -101,7 +101,7 @@ namespace hgl if(!_Delete(index,num)) return(false); - return List::DeleteShift(index,num); + return ArrayList::DeleteShift(index,num); } virtual bool DeleteByValue(ItemPointer &obj) override ///<删除指定的一个数据 @@ -110,7 +110,7 @@ namespace hgl delete obj; - return List::DeleteByValue(obj); + return ArrayList::DeleteByValue(obj); } virtual int DeleteByValue(ItemPointer *obj_list,int num) override ///<删除指定的一批数据 @@ -119,7 +119,7 @@ namespace hgl dlm->Clear(obj_list,num); - return List::DeleteByValue(obj_list,num); + return ArrayList::DeleteByValue(obj_list,num); } virtual T *operator[](int n)const ///<操作符重载取得指定索引处的数据 diff --git a/inc/hgl/type/Pool.h b/inc/hgl/type/Pool.h index fb5d2a5..0f97271 100644 --- a/inc/hgl/type/Pool.h +++ b/inc/hgl/type/Pool.h @@ -211,6 +211,6 @@ namespace hgl virtual ~PoolWithDLM()=default; };//template class PoolWithDLM:public PoolTemplate - template using Pool =PoolWithDLM, Queue, DataLifecycleManager>; ///<数据池模板 - template using ObjectPool =PoolWithDLM, ObjectQueue, ObjectLifecycleManager>; ///<对象池 + template using Pool =PoolWithDLM, Queue, DataLifecycleManager>; ///<数据池模板 + template using ObjectPool =PoolWithDLM, ObjectQueue, ObjectLifecycleManager>; ///<对象池 }//namespace hgl diff --git a/inc/hgl/type/StringList.h b/inc/hgl/type/StringList.h index 748b521..322c951 100644 --- a/inc/hgl/type/StringList.h +++ b/inc/hgl/type/StringList.h @@ -276,7 +276,7 @@ namespace hgl void Insert(int index,const StringClass &str) ///<在指定位置插入一个字符串 { if(index::Insert(index,new StringClass(str)); + Items.ArrayList::Insert(index,new StringClass(str)); } /** diff --git a/src/FileSystem/EnumFile.cpp b/src/FileSystem/EnumFile.cpp index f483045..650e658 100644 --- a/src/FileSystem/EnumFile.cpp +++ b/src/FileSystem/EnumFile.cpp @@ -10,11 +10,11 @@ namespace hgl { protected: - List *fi_list; + ArrayList *fi_list; public: - OnlyFileEnum(List *lfi) + OnlyFileEnum(ArrayList *lfi) { fi_list=lfi; } @@ -26,7 +26,7 @@ namespace hgl };//class OnlyFileEnum:public EnumFile }//namespace - int GetFileInfoList(List &fi_list,const OSString &folder_name,bool proc_folder,bool proc_file,bool sub_folder) + int GetFileInfoList(ArrayList &fi_list,const OSString &folder_name,bool proc_folder,bool proc_file,bool sub_folder) { EnumFileConfig efc(folder_name); diff --git a/src/Log/Loginfo.cpp b/src/Log/Loginfo.cpp index aca320e..aea8e1c 100644 --- a/src/Log/Loginfo.cpp +++ b/src/Log/Loginfo.cpp @@ -9,7 +9,7 @@ namespace hgl { namespace logger { - RWLockObject> log_list; //记录器列表 + RWLockObject> log_list; //记录器列表 bool AddLogger(Logger *log) { diff --git a/src/Text/ConstStringSetSaveToTextStream.cpp b/src/Text/ConstStringSetSaveToTextStream.cpp index 9a73253..e4b16b6 100644 --- a/src/Text/ConstStringSetSaveToTextStream.cpp +++ b/src/Text/ConstStringSetSaveToTextStream.cpp @@ -17,7 +17,7 @@ namespace hgl SC id_str[16]; const SC gap_str[4]={SC(' '),SC(':'),SC(' '),0}; - const List> &csv_list=css->GetConstStringList(); + const ArrayList> &csv_list=css->GetConstStringList(); for(auto &csv:csv_list) {