From b3dba4347722d78a00112b57888652119f062ec6 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 25 Apr 2025 01:05:19 +0800 Subject: [PATCH] =?UTF-8?q?IndexedList<>=E5=A2=9E=E5=8A=A0Exchange,Insert?= =?UTF-8?q?=E4=B8=A4=E4=B8=AA=E6=88=90=E5=91=98=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/type/IndexedList.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/inc/hgl/type/IndexedList.h b/inc/hgl/type/IndexedList.h index dc3f185..2e47296 100644 --- a/inc/hgl/type/IndexedList.h +++ b/inc/hgl/type/IndexedList.h @@ -278,6 +278,41 @@ namespace hgl return !(index<0||index>=data_index.GetCount()); } + virtual void Exchange(int32 a,int32 b) + { + if(!IsValidIndex(a))return; + if(!IsValidIndex(b))return; + + data_index.Exchange(a,b); + } + + virtual bool Insert(int32 pos,const T &value) + { + if(pos<0)return(false); + if(pos>data_index.GetCount())return(false); + if(pos==data_index.GetCount()) + { + return Add(value)>=0; + } + + int32 index; + + if(free_index.IsEmpty()) + { + index=data_array.GetCount(); + data_array.AddCount(1); + data_index.Insert(pos,index); + } + else + { + free_index.Pop(index); + data_index.Insert(pos,index); + } + + hgl_cpy(data_array[index],value); + return true; + } + /** * 删除数据 * @param start 起始删除的数据索引