diff options
Diffstat (limited to 'src/regex/regex.c')
-rw-r--r-- | src/regex/regex.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/regex/regex.c b/src/regex/regex.c index 637eac00d..3281ff469 100644 --- a/src/regex/regex.c +++ b/src/regex/regex.c | |||
@@ -1687,7 +1687,7 @@ dfa_compress_paths_helper (struct GNUNET_REGEX_Automaton *dfa, | |||
1687 | // || cur->transition_count > 1 | 1687 | // || cur->transition_count > 1 |
1688 | || GNUNET_YES == cur->marked) || (start != dfa->start && max_len > 0 && | 1688 | || GNUNET_YES == cur->marked) || (start != dfa->start && max_len > 0 && |
1689 | max_len == strlen (label)) || | 1689 | max_len == strlen (label)) || |
1690 | (start == dfa->start && GNUNET_REGEX_INITIAL_BITS == strlen (label)))) | 1690 | (start == dfa->start && GNUNET_REGEX_INITIAL_BYTES == strlen (label)))) |
1691 | { | 1691 | { |
1692 | t = GNUNET_malloc (sizeof (struct GNUNET_REGEX_Transition)); | 1692 | t = GNUNET_malloc (sizeof (struct GNUNET_REGEX_Transition)); |
1693 | t->label = GNUNET_strdup (label); | 1693 | t->label = GNUNET_strdup (label); |
@@ -2482,17 +2482,26 @@ construct_dfa_states (struct GNUNET_REGEX_Context *ctx, | |||
2482 | } | 2482 | } |
2483 | } | 2483 | } |
2484 | 2484 | ||
2485 | |||
2486 | /** | 2485 | /** |
2487 | * Construct DFA for the given 'regex' of length 'len' | 2486 | * Construct DFA for the given 'regex' of length 'len'. |
2488 | * | 2487 | * |
2489 | * @param regex regular expression string | 2488 | * Path compression means, that for example a DFA o -> a -> b -> c -> o will be |
2490 | * @param len length of the regular expression | 2489 | * compressed to o -> abc -> o. Note that this parameter influences the |
2490 | * non-determinism of states of the resulting NFA in the DHT (number of outgoing | ||
2491 | * edges with the same label). For example for an application that stores IPv4 | ||
2492 | * addresses as bitstrings it could make sense to limit the path compression to | ||
2493 | * 4 or 8. | ||
2491 | * | 2494 | * |
2492 | * @return DFA, needs to be freed using GNUNET_REGEX_destroy_automaton | 2495 | * @param regex regular expression string. |
2496 | * @param len length of the regular expression. | ||
2497 | * @param max_path_len limit the path compression length to the | ||
2498 | * given value. If set to 1, no path compression is applied. Set to 0 for | ||
2499 | * maximal possible path compression (generally not desireable). | ||
2500 | * @return DFA, needs to be freed using GNUNET_REGEX_automaton_destroy. | ||
2493 | */ | 2501 | */ |
2494 | struct GNUNET_REGEX_Automaton * | 2502 | struct GNUNET_REGEX_Automaton * |
2495 | GNUNET_REGEX_construct_dfa (const char *regex, const size_t len) | 2503 | GNUNET_REGEX_construct_dfa (const char *regex, const size_t len, |
2504 | int max_path_len) | ||
2496 | { | 2505 | { |
2497 | struct GNUNET_REGEX_Context ctx; | 2506 | struct GNUNET_REGEX_Context ctx; |
2498 | struct GNUNET_REGEX_Automaton *dfa; | 2507 | struct GNUNET_REGEX_Automaton *dfa; |
@@ -2535,7 +2544,8 @@ GNUNET_REGEX_construct_dfa (const char *regex, const size_t len) | |||
2535 | automaton_create_proofs (dfa); | 2544 | automaton_create_proofs (dfa); |
2536 | 2545 | ||
2537 | // Compress DFA paths | 2546 | // Compress DFA paths |
2538 | dfa_compress_paths (&ctx, dfa, 8); | 2547 | if (1 != max_path_len) |
2548 | dfa_compress_paths (&ctx, dfa, max_path_len); | ||
2539 | 2549 | ||
2540 | // Add strides to DFA | 2550 | // Add strides to DFA |
2541 | //GNUNET_REGEX_dfa_add_multi_strides (&ctx, dfa, 2); | 2551 | //GNUNET_REGEX_dfa_add_multi_strides (&ctx, dfa, 2); |
@@ -2770,7 +2780,7 @@ GNUNET_REGEX_get_first_key (const char *input_string, size_t string_len, | |||
2770 | 2780 | ||
2771 | size = | 2781 | size = |
2772 | string_len < | 2782 | string_len < |
2773 | GNUNET_REGEX_INITIAL_BITS ? string_len : GNUNET_REGEX_INITIAL_BITS; | 2783 | GNUNET_REGEX_INITIAL_BYTES ? string_len : GNUNET_REGEX_INITIAL_BYTES; |
2774 | 2784 | ||
2775 | if (NULL == input_string) | 2785 | if (NULL == input_string) |
2776 | { | 2786 | { |
@@ -2931,7 +2941,7 @@ GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a, | |||
2931 | s->marked = GNUNET_NO; | 2941 | s->marked = GNUNET_NO; |
2932 | } | 2942 | } |
2933 | 2943 | ||
2934 | iterate_initial_edge (GNUNET_REGEX_INITIAL_BITS, GNUNET_REGEX_INITIAL_BITS, | 2944 | iterate_initial_edge (GNUNET_REGEX_INITIAL_BYTES, GNUNET_REGEX_INITIAL_BYTES, |
2935 | NULL, a->start, iterator, iterator_cls); | 2945 | NULL, a->start, iterator, iterator_cls); |
2936 | } | 2946 | } |
2937 | 2947 | ||