summaryrefslogtreecommitdiff
path: root/src/maps
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2013-04-06 13:14:43 +0200
committerPaul Buetow <paul@buetow.org>2013-04-06 13:14:43 +0200
commit796609174e5ecb35fab992969e7690186840048a (patch)
tree1e4370d47f2a5c050b768c228e73e028a6611cb8 /src/maps
parent312fe18cb5f97143f3600b207e979bc559256b6f (diff)
tagging ychat-0.7.3ychat-0.7.3
Diffstat (limited to 'src/maps')
-rw-r--r--src/maps/hmap.h6
-rw-r--r--src/maps/hmap.tmpl11
-rw-r--r--src/maps/smap.h1
-rw-r--r--src/maps/smap.tmpl8
4 files changed, 21 insertions, 5 deletions
diff --git a/src/maps/hmap.h b/src/maps/hmap.h
index a0824ec..38ea2e4 100644
--- a/src/maps/hmap.h
+++ b/src/maps/hmap.h
@@ -9,11 +9,6 @@
using namespace std;
-// void add_elem( obj_type x, key_type k ) --> Insert x
-// void del_elem( key_type k ) --> Remove x
-// obj_type get_elem( key_type k ) --> Return item that matches x
-// void make_empty( ) --> Remove all items
-
template <class obj_type, class key_type>
class hmap
{
@@ -77,6 +72,7 @@ public:
virtual void make_empty( );
virtual void make_empty( void (*func)(key_type) );
virtual void del_elem ( const key_type &k );
+ virtual void rename_key ( const key_type &k1, const key_type &k2 );
virtual obj_type set_elem ( const obj_type &x, const key_type &k );
virtual void run_func( void (*func)(obj_type) );
diff --git a/src/maps/hmap.tmpl b/src/maps/hmap.tmpl
index 10facac..dcd0426 100644
--- a/src/maps/hmap.tmpl
+++ b/src/maps/hmap.tmpl
@@ -104,6 +104,17 @@ void hmap<obj_type, key_type>::del_elem( const key_type & k )
array[ i_current_pos ].info = DELETED;
}
+// Remove item x from the hash table.
+template <class obj_type, class key_type>
+void hmap<obj_type, key_type>::rename_key( const key_type & k1, const key_type & k2 )
+{
+ int i_current_pos = find_pos( k1 );
+ if( is_active( i_current_pos ) ) {
+ array[ i_current_pos ].info = DELETED;
+ add_elem( array[ i_current_pos ].element, k2 );
+ }
+}
+
// Finds item x and resets its value.
template <class obj_type, class key_type>
obj_type hmap<obj_type, key_type>::set_elem( const obj_type & x, const key_type & k )
diff --git a/src/maps/smap.h b/src/maps/smap.h
index e056519..2096139 100644
--- a/src/maps/smap.h
+++ b/src/maps/smap.h
@@ -30,6 +30,7 @@ class smap : public hmap<obj_type, key_type>
void add_elem ( const obj_type &x, const key_type &k );
obj_type set_elem ( const obj_type &x, const key_type &k );
void del_elem ( const key_type &k );
+ void rename_key ( const key_type &k1, const key_type &k2 );
bool is_avail ( const key_type &k );
obj_type get_elem ( const key_type &k );
obj_type pop_elem ( const key_type &k );
diff --git a/src/maps/smap.tmpl b/src/maps/smap.tmpl
index 3167504..5ec7d38 100644
--- a/src/maps/smap.tmpl
+++ b/src/maps/smap.tmpl
@@ -77,6 +77,14 @@ smap<obj_type, key_type>::del_elem( const key_type & k )
pthread_mutex_unlock( &mut_smap );
}
+template <class obj_type, class key_type> void
+smap<obj_type, key_type>::rename_key( const key_type & k1, const key_type & k2 )
+{
+ pthread_mutex_lock ( &mut_smap );
+ hmap<obj_type,key_type>::rename_key( k1, k2 );
+ pthread_mutex_unlock( &mut_smap );
+}
+
template <class obj_type, class key_type>
obj_type smap<obj_type, key_type>::get_elem( const key_type &k )