gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r21774 - gnunet/src/regex


From: gnunet
Subject: [GNUnet-SVN] r21774 - gnunet/src/regex
Date: Wed, 6 Jun 2012 12:54:07 +0200

Author: szengel
Date: 2012-06-06 12:54:07 +0200 (Wed, 06 Jun 2012)
New Revision: 21774

Modified:
   gnunet/src/regex/regex.c
   gnunet/src/regex/test_regex_iterate_api.c
Log:
Better proofs


Modified: gnunet/src/regex/regex.c
===================================================================
--- gnunet/src/regex/regex.c    2012-06-06 09:37:15 UTC (rev 21773)
+++ gnunet/src/regex/regex.c    2012-06-06 10:54:07 UTC (rev 21774)
@@ -817,6 +817,7 @@
   char *R_last[a->state_count][a->state_count];
   char *R_cur[a->state_count][a->state_count];
   char *temp;
+  int length;
 
   k = 0;
   n = a->state_count;
@@ -849,16 +850,17 @@
         }
       }
 
+      if (NULL != R_last[i][j] && 1 < strlen (R_last[i][j]))
+      {
+        temp = R_last[i][j];
+        GNUNET_asprintf (&R_last[i][j], "(%s)", R_last[i][j]);
+        GNUNET_free (temp);
+      }
+
       if (i == j)
       {
         if (NULL == R_last[i][j])
           GNUNET_asprintf (&R_last[i][j], "");
-        else if (1 < strlen (R_last[i][j]))
-        {
-          temp = R_last[i][j];
-          GNUNET_asprintf (&R_last[i][j], "(%s)", R_last[i][j]);
-          GNUNET_free (temp);
-        }
       }
     }
   }
@@ -870,33 +872,51 @@
     {
       for (j = 0; j < n; j++)
       {
+        // 0*R = R*0 = 0
+        // 0+R = R+0 = R
         if (NULL == R_last[i][k] || NULL == R_last[k][j])
         {
           if (NULL != R_last[i][j])
             R_cur[i][j] = GNUNET_strdup (R_last[i][j]);
         }
-        else if (NULL == R_last[i][j] ||
-                 0 == strcmp (R_last[i][j], R_last[i][k]))
-        {
-          if ((R_last[k][k][0] == '(' &&
-               R_last[k][k][strlen (R_last[k][k]) - 1] == ')') ||
-              (1 == strlen (R_last[k][k])))
-            GNUNET_asprintf (&R_cur[i][j], "(%s%s*%s)", R_last[i][k],
-                             R_last[k][k], R_last[k][j]);
-          else
-            GNUNET_asprintf (&R_cur[i][j], "(%s(%s)*%s)", R_last[i][k],
-                             R_last[k][k], R_last[k][j]);
-        }
         else
         {
-          if ((R_last[k][k][0] == '(' &&
-               R_last[k][k][strlen (R_last[k][k]) - 1] == ')') ||
-              (1 == strlen (R_last[k][k])))
-            GNUNET_asprintf (&R_cur[i][j], "(%s|%s%s*%s)", R_last[i][j],
-                             R_last[i][k], R_last[k][k], R_last[k][j]);
+          // R(k)ij = R(k-1)ij + R(k-1)ik (R(k-1)kk)* R(k-1)kj
+          length =
+              snprintf (NULL, 0, "(%s|%s(%s)*%s)", R_last[i][j], R_last[i][k],
+                        R_last[k][k], R_last[k][j]) + 1;
+          char *left = GNUNET_malloc (length);
+          char *right = GNUNET_malloc (length);
+
+          if (NULL != R_last[i][j])
+            strcat (left, R_last[i][j]);
+
+          if (NULL != R_last[i][k])
+            strcat (right, R_last[i][k]);
+
+          if (NULL != R_last[k][k] && 0 != strcmp (R_last[k][k], ""))
+          {
+            strcat (right, "(");
+            strcat (right, R_last[k][k]);
+            strcat (right, ")*");
+          }
+
+          if (NULL != R_last[k][j])
+            strcat (right, R_last[k][j]);
+
+          if (0 == strcmp (left, right) || 0 == strcmp (left, "") ||
+              0 == strcmp (right, ""))
+          {
+            if (0 == strcmp (left, ""))
+              GNUNET_asprintf (&R_cur[i][j], "%s", right);
+            else
+              GNUNET_asprintf (&R_cur[i][j], "%s", left);
+          }
           else
-            GNUNET_asprintf (&R_cur[i][j], "(%s|%s(%s)*%s)", R_last[i][j],
-                             R_last[i][k], R_last[k][k], R_last[k][j]);
+            GNUNET_asprintf (&R_cur[i][j], "(%s|%s)", left, right);
+
+          GNUNET_free_non_null (left);
+          GNUNET_free_non_null (right);
         }
       }
     }
@@ -917,10 +937,12 @@
     }
   }
 
-  // assign proofs
+  // assign proofs and hashes
   for (i = 0; i < n; i++)
   {
     states[i]->proof = GNUNET_strdup (R_last[a->start->marked][i]);
+    GNUNET_CRYPTO_hash (states[i]->proof, strlen (states[i]->proof),
+                        &states[i]->hash);
   }
 
   // cleanup

Modified: gnunet/src/regex/test_regex_iterate_api.c
===================================================================
--- gnunet/src/regex/test_regex_iterate_api.c   2012-06-06 09:37:15 UTC (rev 
21773)
+++ gnunet/src/regex/test_regex_iterate_api.c   2012-06-06 10:54:07 UTC (rev 
21774)
@@ -61,10 +61,14 @@
 
   error = 0;
   /*regex = "ab(c|d)+c*(a(b|c)+d)+(bla)+"; */
+  /*regex = "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*"; */
   /*regex = "z(abc|def)?xyz"; */
-  regex = "1*0(0|1)*";
+  /*regex = "1*0(0|1)*"; */
   /*regex = "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*"; */
-
+  /*regex = 
"abcd:(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)";
 */
+  /*regex = "abc(1|0)*def"; */
+  /*regex = "ab|ac"; */
+  regex = "(ab)(ab)*";
   dfa = GNUNET_REGEX_construct_dfa (regex, strlen (regex));
   GNUNET_REGEX_automaton_save_graph (dfa, "dfa.dot");
   GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, NULL);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]