.NET 实现Hashlist--可以排序的哈希表
2008-12-16 13:35
381 查看
/// <summary>
///
/// </summary>
public abstract class Hashlist : IDictionary, IEnumerable
{
//array list that contains all the keys
//as they are inserted, the index is associated with
//a key so when pulling out values by index
//we can get the key for the index, pull from the
//hashtable the proper value with the corresponding
//key
//This is basically the same as a sorted list but
//does not sort the items, rather it leaves them in the
//order they were inserted - like a list
/// <summary>
///
/// </summary>
protected ArrayList m_oKeys = new ArrayList();
/// <summary>
///
/// </summary>
protected Hashtable m_oValues = new Hashtable();
#region ICollection implementation
//ICollection implementation
/// <summary>
///
/// </summary>
public int Count
{
get{return m_oValues.Count;}
}
/// <summary>
///
/// </summary>
public bool IsSynchronized
{
get{return m_oValues.IsSynchronized;}
}
/// <summary>
///
/// </summary>
public object SyncRoot
{
get{return m_oValues.SyncRoot;}
}
/// <summary>
///
/// </summary>
/// <param name="oArray"></param>
/// <param name="iArrayIndex"></param>
public void CopyTo(System.Array oArray, int iArrayIndex)
{
m_oValues.CopyTo(oArray, iArrayIndex);
}
#endregion
#region IDictionary implementation
//IDictionary implementation
/// <summary>
///
/// </summary>
/// <param name="oKey"></param>
/// <param name="oValue"></param>
public void Add(object oKey, object oValue)
{
m_oKeys.Add(oKey);
m_oValues.Add(oKey, oValue);
}
/// <summary>
///
/// </summary>
public bool IsFixedSize
{
get{return m_oKeys.IsFixedSize;}
}
/// <summary>
///
/// </summary>
public bool IsReadOnly
{
get{return m_oKeys.IsReadOnly;}
}
/// <summary>
///
/// </summary>
public ICollection Keys
{
get{return m_oValues.Keys;}
}
/// <summary>
///
/// </summary>
public void Clear()
{
m_oValues.Clear();
m_oKeys.Clear();
}
/// <summary>
///
/// </summary>
/// <param name="oKey"></param>
/// <returns></returns>
public bool Contains(object oKey)
{
return m_oValues.Contains(oKey);
}
/// <summary>
///
/// </summary>
/// <param name="oKey"></param>
/// <returns></returns>
public bool ContainsKey(object oKey)
{
return m_oValues.ContainsKey(oKey);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public IDictionaryEnumerator GetEnumerator()
{
return m_oValues.GetEnumerator();
}
/// <summary>
///
/// </summary>
/// <param name="oKey"></param>
public void Remove(object oKey)
{
m_oValues.Remove(oKey);
m_oKeys.Remove(oKey);
}
/// <summary>
///
/// </summary>
public object this[object oKey]
{
get{return m_oValues[oKey];}
set{m_oValues[oKey] = value;}
}
/// <summary>
///
/// </summary>
public ICollection Values
{
get{return m_oValues.Values;}
}
#endregion
#region IEnumerable implementation
IEnumerator IEnumerable.GetEnumerator()
{
return m_oValues.GetEnumerator();
}
#endregion
#region Hashlist specialized implementation
//specialized indexer routines
/// <summary>
///
/// </summary>
public object this[string Key]
{
get{return m_oValues[Key];}
}
/// <summary>
///
/// </summary>
public object this[int Index]
{
get{return m_oValues[m_oKeys[Index]];}
}
#endregion
}
///
/// </summary>
public abstract class Hashlist : IDictionary, IEnumerable
{
//array list that contains all the keys
//as they are inserted, the index is associated with
//a key so when pulling out values by index
//we can get the key for the index, pull from the
//hashtable the proper value with the corresponding
//key
//This is basically the same as a sorted list but
//does not sort the items, rather it leaves them in the
//order they were inserted - like a list
/// <summary>
///
/// </summary>
protected ArrayList m_oKeys = new ArrayList();
/// <summary>
///
/// </summary>
protected Hashtable m_oValues = new Hashtable();
#region ICollection implementation
//ICollection implementation
/// <summary>
///
/// </summary>
public int Count
{
get{return m_oValues.Count;}
}
/// <summary>
///
/// </summary>
public bool IsSynchronized
{
get{return m_oValues.IsSynchronized;}
}
/// <summary>
///
/// </summary>
public object SyncRoot
{
get{return m_oValues.SyncRoot;}
}
/// <summary>
///
/// </summary>
/// <param name="oArray"></param>
/// <param name="iArrayIndex"></param>
public void CopyTo(System.Array oArray, int iArrayIndex)
{
m_oValues.CopyTo(oArray, iArrayIndex);
}
#endregion
#region IDictionary implementation
//IDictionary implementation
/// <summary>
///
/// </summary>
/// <param name="oKey"></param>
/// <param name="oValue"></param>
public void Add(object oKey, object oValue)
{
m_oKeys.Add(oKey);
m_oValues.Add(oKey, oValue);
}
/// <summary>
///
/// </summary>
public bool IsFixedSize
{
get{return m_oKeys.IsFixedSize;}
}
/// <summary>
///
/// </summary>
public bool IsReadOnly
{
get{return m_oKeys.IsReadOnly;}
}
/// <summary>
///
/// </summary>
public ICollection Keys
{
get{return m_oValues.Keys;}
}
/// <summary>
///
/// </summary>
public void Clear()
{
m_oValues.Clear();
m_oKeys.Clear();
}
/// <summary>
///
/// </summary>
/// <param name="oKey"></param>
/// <returns></returns>
public bool Contains(object oKey)
{
return m_oValues.Contains(oKey);
}
/// <summary>
///
/// </summary>
/// <param name="oKey"></param>
/// <returns></returns>
public bool ContainsKey(object oKey)
{
return m_oValues.ContainsKey(oKey);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public IDictionaryEnumerator GetEnumerator()
{
return m_oValues.GetEnumerator();
}
/// <summary>
///
/// </summary>
/// <param name="oKey"></param>
public void Remove(object oKey)
{
m_oValues.Remove(oKey);
m_oKeys.Remove(oKey);
}
/// <summary>
///
/// </summary>
public object this[object oKey]
{
get{return m_oValues[oKey];}
set{m_oValues[oKey] = value;}
}
/// <summary>
///
/// </summary>
public ICollection Values
{
get{return m_oValues.Values;}
}
#endregion
#region IEnumerable implementation
IEnumerator IEnumerable.GetEnumerator()
{
return m_oValues.GetEnumerator();
}
#endregion
#region Hashlist specialized implementation
//specialized indexer routines
/// <summary>
///
/// </summary>
public object this[string Key]
{
get{return m_oValues[Key];}
}
/// <summary>
///
/// </summary>
public object this[int Index]
{
get{return m_oValues[m_oKeys[Index]];}
}
#endregion
}
相关文章推荐
- .NET泛型List实现快速排序、查找功能
- ArrayList和LinkedList都是实现了List接口的类,他们都是元素的容器,用于存放对象的引用; 他们都可以对存放的元素进行增删改查的操作,还可以进行排序。 但是,他们还是有区别的。
- 【源】【通用类】线程安全的、可按3种方式排序的、支持谓词匹配的Hash表——SafeHashList
- Comparator实现List排序
- c# list排序的三种实现方式
- java 中List按照date排序的实现
- java Collections.sort()实现List排序的默认方法和自定义方法
- BitMap算法 .net实现 用于去重并且排序,适用于大型权限管理 ,大数据去重排序
- 点击list控件排序的实现
- List/ArrayList 排序实现
- 基于.NET的分词软件设计与实现V5.0--使用Hashtable和HashSet<T>提高分词效率
- 用泛型List实现集合类及排序功能
- 每日刷题(2015/6/21):对比哈希表和STL map。哈希表是怎么实现的?如果输入数据规模不大, 可以使用什么数据结构来代替哈希表。
- 基于LinkedList实现的固定大小线性排序数据结构
- 按首字母分类并排序显示的列表(二)--给BaseExpandableListAdapter提供数据的HashList
- C++ 简单实现MFC ListControl 点击列头排序
- java Collections.sort()实现List排序的默认方法和自定义方法
- 利用PinYin4j 实现List中的对象按数字,字母, 汉字排序
- Java Collections.sort()实现List排序的默认方法和自定义方法
- 在.net中用CheckBoxList实现单选