summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--filter.c15
-rw-r--r--tests/015/trie.tl49
2 files changed, 58 insertions, 6 deletions
diff --git a/filter.c b/filter.c
index f36cd1a8..491cebbd 100644
--- a/filter.c
+++ b/filter.c
@@ -147,7 +147,7 @@ static val regex_from_trie(val trie)
if (zerop(hash_count(trie))) {
return nil;
} else {
- list_collect_decl (out, ptail);
+ val out = nil;
val cell;
struct hash_iter hi;
@@ -155,12 +155,15 @@ static val regex_from_trie(val trie)
while ((cell = hash_iter_next(&hi)) != nil) {
val rx = regex_from_trie(us_cdr(cell));
- ptail = list_collect(ptail,
- if3(consp(rx) && car(rx) == compound_s,
- cons(compound_s, cons(us_car(cell), cdr(rx))),
- list(compound_s, us_car(cell), rx, nao)));
+ val ry = if3(consp(rx) && car(rx) == compound_s,
+ cons(compound_s, cons(us_car(cell), cdr(rx))),
+ list(compound_s, us_car(cell), rx, nao));
+ if (out)
+ out = list(or_s, ry, out, nao);
+ else
+ out = ry;
}
- return cons(or_s, out);
+ return out;
}
}
/* fallthrough */
diff --git a/tests/015/trie.tl b/tests/015/trie.tl
new file mode 100644
index 00000000..f233c76e
--- /dev/null
+++ b/tests/015/trie.tl
@@ -0,0 +1,49 @@
+(load "../common")
+
+(defvarl tr0 (make-trie))
+(defvarl tr1 (make-trie))
+
+(defvarl dat ; '#"aaa aab aac aba abb abc caa cab cac")
+ '("2" "3" "5" "7" "11" "13" "17" "19" "23" "29" "31" "37" "41"
+ "43" "47" "53" "59" "61" "67" "71" "73" "79" "83" "89" "97" "101"
+ "103" "107" "109" "113" "127" "131" "137" "139" "149" "151" "157"
+ "163" "167" "173" "179" "181" "191" "193" "197" "199" "211" "223"
+ "227" "229" "233" "239" "241" "251" "257" "263" "269" "271" "277"
+ "281" "283" "293" "307" "311" "313" "317" "331" "337" "347" "349"
+ "353" "359" "367" "373" "379" "383" "389" "397" "401" "409" "419"
+ "421" "431" "433" "439" "443" "449" "457" "461" "463" "467" "479"
+ "487" "491" "499" "503" "509" "521" "523" "541" "547" "557" "563"
+ "569" "571" "577" "587" "593" "599" "601" "607" "613" "617" "619"
+ "631" "641" "643" "647" "653" "659" "661" "673" "677" "683" "691"
+ "701" "709" "719" "727" "733" "739" "743" "751" "757" "761" "769"
+ "773" "787" "797" "809" "811" "821" "823" "827" "829" "839" "853"
+ "857" "859" "863" "877" "881" "883" "887" "907" "911" "919" "929"
+ "937" "941" "947" "953" "967" "971" "977" "983" "991" "997"))
+
+(defvarl enu [mapcar tostring (range* 0 (len dat))])
+(defvarl ndt [mapcar (op mapcar (op + 64)) dat])
+(defvarl fdt [mapcar (ret `x@{1}y`) dat])
+(defvarl fen [mapcar (ret `x@{1}y`) enu])
+
+(each ((d dat)
+ (n enu))
+ (trie-add tr0 d n)
+ (trie-add tr1 d n))
+
+(trie-compress tr1)
+
+(defvarl rx0 (regex-compile (regex-from-trie tr0)))
+
+(mvtest
+ (build (each ((d dat)) (add (filter-string-tree tr0 d)))) enu
+ (build (each ((x ndt)) (add (filter-string-tree tr0 x)))) ndt
+ (build (each ((f fdt)) (add (filter-string-tree tr0 f)))) fen)
+
+(mvtest
+ (build (each ((d dat)) (add (filter-string-tree tr1 d)))) enu
+ (build (each ((x ndt)) (add (filter-string-tree tr1 x)))) ndt
+ (build (each ((f fdt)) (add (filter-string-tree tr1 f)))) fen)
+
+(mvtest
+ (build (each ((d dat)) (add [rx0 d]))) dat
+ (build (each ((n enu)) (add [rx0 n]))) (repeat '(nil) (len dat)))