Using HashTable to realize a set which Provide a collection that contains a group of unique objects
2007-05-09 10:41
585 查看
using System;
2using System.Collections;
3namespace Utilities
4{
5 /**//// <summary>
6 /// Provide a collection that contains a group of unique
7 /// objects.
8 /// </summary>
9 public class Set
10 {
11 private Hashtable h = new Hashtable();
12 /**//// <summary>
13 /// Return an enumerator for this set.
14 /// </summary>
15 /// <returns>An enumerator for this set</returns>
16 public IEnumerator GetEnumerator()
17 {
18 return h.Keys.GetEnumerator();
19 }
20 /**//// <summary>
21 /// Add the provided object to this set.
22 /// </summary>
23 /// <param name="o">the object to add</param>
24 public void Add(Object o)
25 {
26 h[o] = null;
27 }
28 /**//// <summary>
29 /// Return true if the set contains the presented object.
30 /// </summary>
31 /// <param name="o">the object of curiosity</param>
32 /// <returns>true, if the set contains the presented object</returns>
33 public bool Contains(Object o)
34 {
35 return h.Contains(o);
36 }
37 }
38}
2using System.Collections;
3namespace Utilities
4{
5 /**//// <summary>
6 /// Provide a collection that contains a group of unique
7 /// objects.
8 /// </summary>
9 public class Set
10 {
11 private Hashtable h = new Hashtable();
12 /**//// <summary>
13 /// Return an enumerator for this set.
14 /// </summary>
15 /// <returns>An enumerator for this set</returns>
16 public IEnumerator GetEnumerator()
17 {
18 return h.Keys.GetEnumerator();
19 }
20 /**//// <summary>
21 /// Add the provided object to this set.
22 /// </summary>
23 /// <param name="o">the object to add</param>
24 public void Add(Object o)
25 {
26 h[o] = null;
27 }
28 /**//// <summary>
29 /// Return true if the set contains the presented object.
30 /// </summary>
31 /// <param name="o">the object of curiosity</param>
32 /// <returns>true, if the set contains the presented object</returns>
33 public bool Contains(Object o)
34 {
35 return h.Contains(o);
36 }
37 }
38}
相关文章推荐
- (NOT CLEAR)Question 21: Which of the following statements provide a valid reason not to use RTTI for distributed (i.e. networked
- Question 24: Which of the following template declarations provide the correct syntax to write a template class
- Crusher the process of using these points we need to remember that
- How-to find the SQL that using lots of temp tablespace in Oracle
- 83.You are using Enterprise Manager to schedule backups for your database. Which type of script woul
- 2 Which of the following cannot be used as input to the SQL Tuning Advisor? (Choose all that apply.)
- 92 Examine the output of the query that you executed to list the objects in the recycle bin: SQL> SE
- An example of using libexif to set JPEG Orientation Tag
- how to solve Error cannot add duplicate collection entry of type add with unique key attribute 'valu
- Using a modeless .NET dialog to display properties of multiple AutoCAD objects
- Using a palette from .NET to display properties of multiple AutoCAD objects
- 102.You want to import schema objects of the HR user using Oracle Data Pump from the development dat
- Failed to Match * of * Components using Unique Identifiers
- Here's an example that shows how to enumerate through the features of a selection set, returning the value of each field in the attribute table except for the geometry colum.
- An example of using libexif to set JPEG Orientation Tag
- Hashtable and HashMap are two hash based collection in Java and used to store objects as key value p
- To get the tree list of the objects on which an object depends
- VizualPV3D (VizualPV3D is a Flash Visualization Application that provides a GUI interface to create and manipulate objects in 3
- How to sort an arbitrarily large set of data using Hadoop?
- Apps using background location services must provide a reason that clarifies the purpose of the use