[Scummvm-cvs-logs] SF.net SVN: scummvm: [21429] scummvm/trunk/common/assocarray.h

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Mar 24 07:25:22 CET 2006


Revision: 21429
Author:   fingolfin
Date:     2006-03-24 07:22:17 -0800 (Fri, 24 Mar 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=21429&view=rev

Log Message:
-----------
Some more cleanup in AssocArray

Modified Paths:
--------------
    scummvm/trunk/common/assocarray.h
Modified: scummvm/trunk/common/assocarray.h
===================================================================
--- scummvm/trunk/common/assocarray.h	2006-03-24 14:30:33 UTC (rev 21428)
+++ scummvm/trunk/common/assocarray.h	2006-03-24 15:22:17 UTC (rev 21429)
@@ -107,8 +107,6 @@
 	int lookup(const Key &index) const;
 	void expand_array(void);
 
-	int nele_val(void) const { return _nele; }
-
 public:
 
 	Val &operator [](const Key &index);
@@ -116,10 +114,20 @@
 	AssocArray(Val default_value);
 	~AssocArray();
 	bool contains(const Key &index) const;
+	Val queryVal(const Key &index) const;
+	void clear(bool shrinkArray = 0);
+
+	// The following two methods are used to return a list of
+	// all the keys / all the values (or rather, duplicates of them).
+	// Currently they aren't used, and I think a better appraoch
+	// is to add iterators, which allow the same in a more C++-style
+	// fashion, do not require making duplicates, and finally
+	// even allow in-place modifications of
 	Key *new_all_keys(void) const;
 	Val *new_all_values(void) const;
-	Val queryVal(const Key &index) const;
-	void clear(bool shrinkArray = 0);
+	
+	
+	// TODO: There is no "remove(key)" method yet.
 };
 
 //-------------------------------------------------------
@@ -144,7 +152,6 @@
 template <class Key, class Val>
 bool AssocArray<Key, Val>::contains(const Key &index) const {
 	int ctr = lookup(index);
-
 	return (_arr[ctr] != NULL);
 }
 
@@ -206,12 +213,11 @@
 	int ctr;
 
 	_arr = new aa_ref_t <Key, Val> *[INIT_SIZE];
+	assert(_arr != NULL);
 
 	for (ctr = 0; ctr < INIT_SIZE; ctr++)
 		_arr[ctr] = NULL;
 
-	assert(_arr != NULL);
-
 	_arrsize = INIT_SIZE;
 	_nele = 0;
 }
@@ -309,10 +315,7 @@
 
 		if (_nele > _arrsize / 2) {
 			expand_array();
-
-			return (*this)[index];
-		} else {
-			return _arr[ctr]->dat;
+			ctr = lookup(index);
 		}
 	}
 
@@ -322,11 +325,8 @@
 template <class Key, class Val>
 Val AssocArray<Key, Val>::queryVal(const Key &index) const {
 	int ctr = lookup(index);
-
-	if (_arr[ctr] == NULL)
-		return _default_value;
-	else
-		return _arr[ctr]->dat;
+	assert(_arr[ctr] != NULL);
+	return _arr[ctr]->dat;
 }
 
 }	// End of namespace Common


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list