regex profiler fixes
[oweals/gnunet.git] / src / include / gnunet_regex_lib.h
index 53e7c13e066168007151651e800eb3d46381a888..e7c525304dcd62bfb4ba6490d3238de3a3d0c646 100644 (file)
@@ -37,6 +37,25 @@ extern "C"
 #endif
 #endif
 
+
+/**
+ * Constant for how many bytes the initial string regex should have.
+ */
+#define GNUNET_REGEX_INITIAL_BYTES 24
+
+
+/**
+ * Maximum regex string length for use with GNUNET_REGEX_ipv4toregex
+ */
+#define GNUNET_REGEX_IPV4_REGEXLEN 32 + 6
+
+
+/**
+ * Maximum regex string length for use with GNUNET_REGEX_ipv6toregex
+ */
+#define GNUNET_REGEX_IPV6_REGEXLEN 128 + 6
+
+
 /**
  * Automaton (NFA/DFA) representation.
  */
@@ -60,28 +79,26 @@ struct GNUNET_REGEX_Edge
 };
 
 
-/**
- * Construct an NFA by parsing the regex string of length 'len'.
- *
- * @param regex regular expression string.
- * @param len length of the string.
- *
- * @return NFA, needs to be freed using GNUNET_REGEX_destroy_automaton.
- */
-struct GNUNET_REGEX_Automaton *
-GNUNET_REGEX_construct_nfa (const char *regex, const size_t len);
-
-
 /**
  * Construct DFA for the given 'regex' of length 'len'.
  *
+ * Path compression means, that for example a DFA o -> a -> b -> c -> o will be
+ * compressed to o -> abc -> o. Note that this parameter influences the
+ * non-determinism of states of the resulting NFA in the DHT (number of outgoing
+ * edges with the same label). For example for an application that stores IPv4
+ * addresses as bitstrings it could make sense to limit the path compression to
+ * 4 or 8.
+ *
  * @param regex regular expression string.
  * @param len length of the regular expression.
- *
- * @return DFA, needs to be freed using GNUNET_REGEX_destroy_automaton.
+ * @param max_path_len limit the path compression length to the
+ *        given value. If set to 1, no path compression is applied. Set to 0 for
+ *        maximal possible path compression (generally not desireable).
+ * @return DFA, needs to be freed using GNUNET_REGEX_automaton_destroy.
  */
 struct GNUNET_REGEX_Automaton *
-GNUNET_REGEX_construct_dfa (const char *regex, const size_t len);
+GNUNET_REGEX_construct_dfa (const char *regex, const size_t len,
+                            int max_path_len);
 
 
 /**
@@ -98,7 +115,6 @@ GNUNET_REGEX_automaton_destroy (struct GNUNET_REGEX_Automaton *a);
  * Options for graph creation function
  * GNUNET_REGEX_automaton_save_graph.
  */
-
 enum GNUNET_REGEX_GraphSavingOptions
 {
   /**
@@ -207,6 +223,32 @@ GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a,
                                 void *iterator_cls);
 
 
+/**
+ * Create a regex in 'rxstr' from the given 'ip' and 'netmask'.
+ *
+ * @param ip IPv4 representation.
+ * @param netmask netmask for the ip.
+ * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV4_REGEXLEN
+ *              bytes long.
+ */
+void
+GNUNET_REGEX_ipv4toregex (const struct in_addr *ip, const char *netmask,
+                          char *rxstr);
+
+
+/**
+ * Create a regex in 'rxstr' from the given 'ipv6' and 'prefixlen'.
+ *
+ * @param ipv6 IPv6 representation.
+ * @param prefixlen length of the ipv6 prefix.
+ * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV6_REGEXLEN
+ *              bytes long.
+ */
+void
+GNUNET_REGEX_ipv6toregex (const struct in6_addr *ipv6,
+                          unsigned int prefixlen, char *rxstr);
+
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif