按C++说明下:
内部维护了一个vector和unordered_map,vector用来存储数据,unordered_map以数据为key,数据在vector的索引为值。
利用unordered_map存储的数据实现对元素的随机查找和删除
不允许Insert
删除需要特殊处理:
这样做的目的是为了保证hash表里存的数组索引是正确的
排序:
排序就是排序数组,然后重新赋值hash表
继承c#的IList接口
//https://referencesource.microsoft.com/#mscorlib/system/collections/generic/ilist.cs,5fd4a456a7fab8b0,references
public interface IList<T> : ICollection<T>
{
// The Item property provides methods to read and edit entries in the List.
T this[int index] {
get;
set;
}
// Returns the index of a particular item, if it is in the list.
// Returns -1 if the item isn't in the list.
int IndexOf(T item);
// Inserts value into the list at position index.
// index must be non-negative and less than or equal to the
// number of elements in the list. If index equals the number
// of items in the list, then value is appended to the end.
void Insert(int index, T item);
// Removes the item at position index.
void RemoveAt(int index);
}
特点:
缺点: