[freenos] r238 committed - Corrected tab invexes and general coding style in the Map class.

  • From: codesite-noreply@xxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Sun, 02 Aug 2009 10:31:13 +0000

Revision: 238
Author: nieklinnenbank
Date: Sun Aug  2 03:25:38 2009
Log: Corrected tab invexes and general coding style in the Map class.

http://code.google.com/p/freenos/source/detail?r=238

Modified:
 /trunk/include/Map.h

=======================================
--- /trunk/include/Map.h        Sat Jun 20 05:19:09 2009
+++ /trunk/include/Map.h        Sun Aug  2 03:25:38 2009
@@ -24,7 +24,8 @@
 #include "Vector.h"
 #include "Comparable.h"

-template <class K = Comparable<class K>, class V = Comparable<class V> > class Map
+template <class K = Comparable<class K>,
+         class V = Comparable<class V> > class Map
 {
     public:

@@ -45,27 +46,27 @@
         */
        void clear()
        {
-               for(Size size = 0; size < _keys.count(); size++ )
-               {
-                       _keys[size] = (K*) NULL;
-                       _values[size] = (V*) NULL;
-               }
+           for(Size size = 0; size < _keys.count(); size++ )
+           {
+               _keys[size] = (K*) NULL;
+               _values[size] = (V*) NULL;
+           }
        }

        /**
-        * Returns a shallow copy of this Map: the keys and values themselves
-        * are not cloned.
+        * @brief Returns a shallow copy of this Map.
+        *        The keys and values themselves are not cloned.
         * @return A shallow clone of this Map.
         */
        Map<K, V> clone()
        {
-               Map<K, V> clone;
-               for(Size index = 0; index < _keys.count(); index++)
-               {
-                       clone.put( _keys[index], _values[index] );
-               }
-
-               return clone;
+           Map<K, V> clone;
+
+           for(Size index = 0; index < _keys.count(); index++)
+           {
+               clone.put( _keys[index], _values[index] );
+           }
+           return clone;
        }

        /**
@@ -74,100 +75,97 @@
         */
        bool containsKey(K* key, bool strict = false)
        {
-               for( Size index = 0; index < _keys.count(); index++ )
-               {
-                       if( ! strict )
-                       {
-                               if( _keys[index]->equals(key) )
-                               {
-                                       return true;
-                               }
-                       } else {
-                               if( _keys[index] == key )
-                               {
-                                       return true;
-                               }
-                       }
-               }
-
-               return false;
+           for( Size index = 0; index < _keys.count(); index++ )
+           {
+               if( ! strict )
+               {
+                   if( _keys[index]->equals(key) )
+                   {
+                       return true;
+                   }
+               } else {
+                   if( _keys[index] == key )
+                   {
+                       return true;
+                   }
+               }
+           }
+           return false;
        }

        /**
         * Returns true if this Map maps one ore more keys to the given value.
- * @return bool Whether this Map maps one ore more keys to the given value.
+        * @return bool Whether this Map maps >= 1 key(s) to the given value.
         */
        bool containsValue(V* value, bool strict = false)
        {
-               for( Size index = 0; index < _values.count(); index++ )
-               {
-                       if( ! strict )
-                       {
-                               if( _values[index]->equals(value) )
-                               {
-                                       return true;
-                               }
-                       } else {
-                               if( _values[index] == value )
-                               {
-                                       return true;
-                               }
-                       }
-               }
-
-               return false;
+           for( Size index = 0; index < _values.count(); index++ )
+           {
+               if( ! strict )
+               {
+                   if( _values[index]->equals(value) )
+                   {
+                       return true;
+                   }
+               } else {
+                   if( _values[index] == value )
+                   {
+                       return true;
+                   }
+               }
+           }
+           return false;
        }

        /**
-        * Returns a shallow clone of the Vector containing the
-        * keys in this Map.
+        * Get a shallow clone of the Vector containing the keys in this Map.
         */
        Vector<K> keys()
        {
-               return _keys.clone();
+           return _keys.clone();
        }

        /**
-        * Returns whether this Map equals the given one.
+        * Compares Map instances.
+        * @param map Map instance.
+        * @return True if equal, false otherwise.
         */
        bool equals(Map<K, V> map)
        {
-               if( *map == this )
-               {
-                       return true;
-               }
-               if( map.size() != this->size() )
-               {
-                       return false;
-               }
-
-               for( Size index = 0; index < _keys.count(); index++ )
-               {
-                       if( ! _keys[index]->equals(map.keys()[index])
-                           || ! _values[index]->equals(map.values()[index]) )
-                       {
-                               return false;
-                       }
-               }
-
-               return true;
+           if( *map == this )
+           {
+               return true;
+           }
+           if( map.size() != this->size() )
+           {
+               return false;
+           }
+
+           for( Size index = 0; index < _keys.count(); index++ )
+           {
+               if( ! _keys[index]->equals(map.keys()[index])
+                || ! _values[index]->equals(map.values()[index]) )
+               {
+                   return false;
+               }
+           }
+           return true;
        }

        /**
-        * Returns the value to which the specified key is mapped,
-        * or NULL if this Map contains no mapping for the key.
-        * @return The value for the given key.
+        * Get value to which the specified key is mapped, or NULL if not 
mapped.
+        * @param key Pointer to the key to lookup.
+        * @return The value for the given key, or NULL if not found.
         */
        V* get(K* key)
        {
-               int index = _getKeyIndex(key);
-
-               if( index != -1 )
-               {
-                       return *(_values[(Size)index]);
-               }
-
-               return (V*) NULL;
+           int index = _getKeyIndex(key);
+
+           if( index != -1 )
+           {
+               return *(_values[(Size)index]);
+           }
+           return (V*) NULL;
        }

        /**
@@ -176,7 +174,7 @@
         */
        int hashCode()
        {
-               return 0;
+           return 0;
        }

        /**
@@ -184,7 +182,7 @@
         */
        bool isEmpty()
        {
-               return (_keys.count() == 0);
+           return (_keys.count() == 0);
        }

        /**
@@ -192,17 +190,16 @@
         */
        V* put(K* key, V* value)
        {
-               int index = _getKeyIndex(key);
-
-               if( index == -1 )
-               {
-                       _keys.insert(key);
-                       _values.insert(value);
-               } else {
-                       _values.insert( (Size)index, value);
-               }
-
-               return value;
+           int index = _getKeyIndex(key);
+
+           if( index == -1 )
+           {
+               _keys.insert(key);
+               _values.insert(value);
+           } else {
+               _values.insert( (Size)index, value);
+           }
+           return value;
        }

        /**
@@ -210,17 +207,16 @@
         */
        V* remove(K* key)
        {
-               int index = _getKeyIndex(key);
-
-               if( index != -1 )
-               {
-                       _keys.remove( (Size)index );
-                       V* value = _values[index];
-                       _values.remove( (Size)index );
-                       return value;
-               }
-
-               return (V*) NULL;
+           int index = _getKeyIndex(key);
+
+           if( index != -1 )
+           {
+               _keys.remove( (Size)index );
+               V* value = _values[index];
+               _values.remove( (Size)index );
+               return value;
+           }
+           return (V*) NULL;
        }

        /**
@@ -228,7 +224,7 @@
         */
        Size size()
        {
-               return _keys.size();
+           return _keys.size();
        }

        /**
@@ -236,27 +232,28 @@
         */
        Vector<V> values()
        {
-               return _values.clone();
+           return _values.clone();
        }

     private:

+       /** Known keys in the Map. */
        Vector<K> _keys;
+
+       /** Values in the Map. */
        Vector<V> _values;

        int _getKeyIndex(K* key)
        {
-               for( Size index = 0; index < _keys.count(); index++ )
-               {
-                       if( _keys[index]->equals(key) )
-                       {
-                               return (int)index;
-                       }
-               }
-
-               return -1;
+           for( Size index = 0; index < _keys.count(); index++ )
+           {
+               if( _keys[index]->equals(key) )
+               {
+                   return (int)index;
+               }
+           }
+           return -1;
        }
 };

-
 #endif /* __MAP_H */

Other related posts:

  • » [freenos] r238 committed - Corrected tab invexes and general coding style in the Map class. - codesite-noreply