diff mbox

[1/6] hash_set: add iterator and remove method.

Message ID 36a7bfbc47fed748ed0f11593d41f24ee0b2939f.1436438929.git.mliska@suse.cz
State New
Headers show

Commit Message

Martin Liška July 9, 2015, 9:13 a.m. UTC
gcc/ChangeLog:

2015-07-03  Martin Liska  <mliska@suse.cz>

	* hash-set.h (remove): New function.
	(iterator): New iteration class for hash_set.
---
 gcc/hash-set.h | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

Comments

Jeff Law July 9, 2015, 5:06 p.m. UTC | #1
On 07/09/2015 03:13 AM, mliska wrote:
> gcc/ChangeLog:
>
> 2015-07-03  Martin Liska  <mliska@suse.cz>
>
> 	* hash-set.h (remove): New function.
> 	(iterator): New iteration class for hash_set.
OK.
jeff
diff mbox

Patch

diff --git a/gcc/hash-set.h b/gcc/hash-set.h
index 2fb6cae..e85af2a 100644
--- a/gcc/hash-set.h
+++ b/gcc/hash-set.h
@@ -59,6 +59,11 @@  public:
       return !Traits::is_empty (e);
     }
 
+  void remove (const Key &k)
+    {
+      m_table.remove_elt_with_hash (k, Traits::hash (k));
+    }
+
   /* Call the call back on each pair of key and value with the passed in
      arg.  */
 
@@ -74,6 +79,40 @@  public:
 
   size_t elements () const { return m_table.elements (); }
 
+  class iterator
+  {
+  public:
+    explicit iterator (const typename hash_table<Traits>::iterator &iter) :
+      m_iter (iter) {}
+
+    iterator &operator++ ()
+      {
+	++m_iter;
+	return *this;
+      }
+
+    Key
+    operator* ()
+      {
+	return *m_iter;
+      }
+
+    bool
+    operator != (const iterator &other) const
+      {
+	return m_iter != other.m_iter;
+      }
+
+  private:
+    typename hash_table<Traits>::iterator m_iter;
+  };
+
+  /* Standard iterator retrieval methods.  */
+
+  iterator begin () const { return iterator (m_table.begin ()); }
+  iterator end () const { return iterator (m_table.end ()); }
+
+
 private:
 
   template<typename T, typename U> friend void gt_ggc_mx (hash_set<T, U> *);