ecere/Containers: Improved support for Map with 'struct' key
authorJerome St-Louis <jerome@ecere.com>
Thu, 13 Oct 2011 06:46:53 +0000 (02:46 -0400)
committerJerome St-Louis <jerome@ecere.com>
Thu, 13 Oct 2011 06:46:53 +0000 (02:46 -0400)
ecere/src/com/containers/Map.ec

index f5a7819..daa616c 100644 (file)
@@ -41,11 +41,7 @@ public struct MapIterator<class KT, class V> : Iterator<V, IT = KT>
    }
    property KT key
    {
-      get
-      {
-         MapNode<T, V> node = (MapNode<T, V>)pointer;
-         return node.key;
-      }
+      get { return ((Map<KT, V>)container).GetKey((MapNode<KT, V>)pointer); }
    }
    property V value
    {
@@ -58,7 +54,14 @@ public class Map<class MT, class V> : CustomAVLTree<MapNode<MT, V>, I = MT, D =
 {
    class_fixed
 
-   MT GetData(MapNode<MT, V> node)
+   MT GetKey(MapNode<KT, V> node)
+   {
+      if(class(MT).type == structClass)
+         return (MT)(((byte *)&(uint64)node.key) + __ENDIAN_PAD(sizeof(void *)));
+      return node.key;
+   }
+
+   V GetData(MapNode<MT, V> node)
    {
       if(node)
       {