ecere; compiler/libec: (#234, #361) Fixed isblank issue with GCC 3.4.5
[sdk] / ecere / src / com / BTNode.ec
index 609bded..beacf3c 100644 (file)
@@ -7,7 +7,7 @@ import "instance"
 public enum TreePrintStyle { inOrder, postOrder, preOrder, depthOrder };
 
 // WARNING: This function has no boundary check!
-public void strcatf(char * string, char * format, ...)
+public void strcatf(char * string, const char * format, ...)
 {
    va_list args;
    va_start(args, format);
@@ -29,7 +29,7 @@ public:
       {
          bool truth = true;
          channel.Serialize(truth);
-         channel.Serialize(key);
+         channel.Serialize((uint)key); // Serialize/Deserialize as 32 bit for compatibility (e.g. EDB)
          channel.Serialize(left);
          channel.Serialize(right);
       }
@@ -48,7 +48,7 @@ public:
       {
          // TODO: Fix typed_object issues
          this = eInstance_New(class(BTNode));
-         channel.Unserialize(key);
+         { uint k; channel.Unserialize(k); key = k; }
          channel.Unserialize(left);
          if(left) { left.parent = this; }
          channel.Unserialize(right);
@@ -121,7 +121,7 @@ public:
 private:
 
    void Free(void (*FreeKey)(void * key))
-   {  
+   {
        if (left) left.Free(FreeKey);
        if (right) right.Free(FreeKey);
       if(FreeKey) FreeKey((void *)key);
@@ -216,13 +216,13 @@ private:
       return this;
    }
 
-   public BTNode FindString(char * key)
+   public BTNode FindString(const char * key)
    {
       while(this)
       {
          int result;
          if(key && this.key)
-            result = strcmp(key, (char *)this.key);
+            result = strcmp(key, (const char *)this.key);
          else if(key && !this.key)
             result = 1;
          else if(!key && this.key)
@@ -240,7 +240,7 @@ private:
       return this;
    }
 
-   public BTNode FindPrefix(char * key)
+   public BTNode FindPrefix(const char * key)
    {
       BTNode subString = null;
       int len = key ? strlen(key) : 0;
@@ -248,7 +248,7 @@ private:
       {
          int result;
          if(key && this.key)
-            result = strcmp(key, (char *)this.key);
+            result = strcmp(key, (const char *)this.key);
          else if(key && !this.key)
             result = 1;
          else if(!key && this.key)
@@ -258,7 +258,7 @@ private:
 
          if(result < 0)
          {
-            if(!strncmp(key, (char *)this.key, len))
+            if(!strncmp(key, (const char *)this.key, len))
                subString = this;
             this = left;
          }
@@ -318,13 +318,13 @@ private:
          }
       }
 
-      //if(!swap.left) 
+      //if(!swap.left)
       {
          swap.left = left;
          if(left)
             left.parent = swap;
       }
-      //if(!swap.right) 
+      //if(!swap.right)
       {
           swap.right = right;
           if (right)
@@ -368,7 +368,7 @@ private:
          return parent.Rebalance();
       else
          return null;
-   }      
+   }
 
    BTNode RemoveSwapRight()
    {
@@ -522,7 +522,7 @@ private:
 
    #define NUMSIZE   4
 
-   char * Print(char * output, TreePrintStyle tps) 
+   char * Print(char * output, TreePrintStyle tps)
    {
       switch(tps)
       {
@@ -540,7 +540,7 @@ private:
 
             if(tps == postOrder) strcatf(output, "%d ", key);
 
-               return output;          
+            return output;
          }
          case depthOrder:
          {
@@ -561,7 +561,7 @@ private:
       return null;
    }
 
-   void PrintDepth(char * output, int wantedDepth, int curDepth, int maxDepth, bool last) 
+   void PrintDepth(char * output, int wantedDepth, int curDepth, int maxDepth, bool last)
    {
       int c;
       if(wantedDepth == curDepth)
@@ -570,7 +570,7 @@ private:
          int len;
 
          if(this)
-            sprintf(nodeString, "%d", key);
+            sprintf(nodeString, "%d", (int)key);
 
          len = strlen(nodeString);
          for(c = 0; c<(NUMSIZE - len)/2; c++)
@@ -607,7 +607,7 @@ private:
       {
          if(left.parent != this)
          {
-            printf("Parent not set properly at node %d\n", left.key);
+            printf("Parent not set properly at node %d\n", (int)left.key);
             valid = false;
          }
          valid *= left.Check(tree);
@@ -616,7 +616,7 @@ private:
       {
          if(right.parent != this)
          {
-            printf("Parent not set properly at node %d\n", right.key);
+            printf("Parent not set properly at node %d\n", (int)right.key);
             valid = false;
          }
          valid *= right.Check(tree);
@@ -624,40 +624,38 @@ private:
 
       if(depth != depthProp)
       {
-         printf("Depth value at node %d (%d) doesn't match depth property (%d)\n", key, depth, depthProp);
+         printf("Depth value at node %d (%d) doesn't match depth property (%d)\n", (int)key, depth, depthProp);
          valid = 0;
       }
 
       if (diffHeight < -1 || diffHeight > 1)
       {
          valid = 0;
-         printf("Height difference is %d at node %d\n", diffHeight, key);
+         printf("Height difference is %d at node %d\n", diffHeight, (int)key);
       }
 
       // Verify that balance-factor is correct
       if (diffHeight != balanceFactor)
       {
          valid = 0;
-         printf("Height difference %d doesnt match balance-factor of %d at node \n", diffHeight, balanceFactor, key);
+         printf("Height difference %d doesnt match balance-factor of %d at node %d\n", diffHeight, balanceFactor, (int)key);
       }
 
       // Verify that search-tree property is satisfied
       if (left && tree.CompareKey(tree, left.key, key) > 0)
       {
          valid = false;
-         printf("Node %d is *smaller* than left subtree %d\n", key, left.key);
+         printf("Node %d is *smaller* than left subtree %d\n", (int)key, (int)left.key);
       }
       if (right && tree.CompareKey(tree, right.key, key) < 0)
       {
          valid = false;
-         printf("Node %d is *greater* than right subtree %d\n", key, right.key);
+         printf("Node %d is *greater* than right subtree %d\n", (int)key, (int)right.key);
       }
       return valid;
    }
 };
 
-// TODO: WHY CAN'T WE HAVE THIS ABOVE?
-
 public class StringBTNode : struct // BTNode
 {
    class_fixed
@@ -689,8 +687,7 @@ public:
       channel.Unserialize(truth);
       if(truth)
       {
-         // TODO: Fix typed_object issues
-         this = eInstance_New(class(StringBTNode));
+         this = { };
          channel.Unserialize(key);
          channel.Unserialize(left);
          if(left) { left.parent = this; }