Commit 6730102e36778240a28c2e66b3da9e317180da03
1 parent
5265d902
maj lib
Showing
3 changed files
with
40 additions
and
3 deletions
Show diff stats
anubis_dev/library/tools/2-4tree.anubis
1 | Author : Matthieu Herrmann | 1 | Author : Matthieu Herrmann |
2 | Creation : 2014/04/14 | 2 | Creation : 2014/04/14 |
3 | - Last update : 2014/10/02 13:56 by matthieu@embryo (inserted by vim). | 3 | + Last update : 2015/02/26 11:30 by matthieu@Embryo (inserted by vim). |
4 | ====================================================================================================================== | 4 | ====================================================================================================================== |
5 | Library import: | 5 | Library import: |
6 | read tools/basis.anubis | 6 | read tools/basis.anubis |
@@ -125,6 +125,16 @@ public define Tree($Entry) insert( | @@ -125,6 +125,16 @@ public define Tree($Entry) insert( | ||
125 | Tree($Entry) tr | 125 | Tree($Entry) tr |
126 | ). | 126 | ). |
127 | 127 | ||
128 | + | ||
129 | + *** (2.4) Operators | ||
130 | + ================================================================================================================ | ||
131 | + | ||
132 | +public define inline Tree($Entry) Tree($Entry) l + Tree($Entry) r. | ||
133 | + | ||
134 | +public define inline Tree($Entry) Tree($Entry) l - Tree($Entry) r. | ||
135 | + | ||
136 | +public define inline Tree($Entry) Tree($Entry) l - $Entry r. | ||
137 | + | ||
128 | *** (3) Searching | 138 | *** (3) Searching |
129 | ================================================================================================================== | 139 | ================================================================================================================== |
130 | 140 | ||
@@ -1967,6 +1977,23 @@ public define Tree($Entry) insert( | @@ -1967,6 +1977,23 @@ public define Tree($Entry) insert( | ||
1967 | Tree($Entry) tr | 1977 | Tree($Entry) tr |
1968 | ) = insert(take_left(l), tr). | 1978 | ) = insert(take_left(l), tr). |
1969 | 1979 | ||
1980 | + | ||
1981 | + *** [10] Operators | ||
1982 | + ================================================================================================================== | ||
1983 | + | ||
1984 | +public define inline Tree($Entry) Tree($Entry) l + Tree($Entry) r = union(l, r). | ||
1985 | + | ||
1986 | +public define inline Tree($Entry) Tree($Entry) l - $Entry r = remove(r, l). | ||
1987 | + | ||
1988 | +public define inline Tree($Entry) Tree($Entry) l - Tree($Entry) r = | ||
1989 | + fold_left(take_left(r), l, (Tree($Entry) t, $Entry e)|-> t - e). | ||
1990 | + | ||
1991 | + | ||
1992 | + | ||
1993 | + | ||
1994 | + | ||
1995 | + | ||
1996 | + | ||
1970 | ====================================================================================================================== | 1997 | ====================================================================================================================== |
1971 | = Testing part ======================================================================================================= | 1998 | = Testing part ======================================================================================================= |
1972 | ====================================================================================================================== | 1999 | ====================================================================================================================== |
anubis_dev/library/tools/finger_trees.anubis
1 | Author : Matthieu Herrmann | 1 | Author : Matthieu Herrmann |
2 | Creation : 2014/02/10 | 2 | Creation : 2014/02/10 |
3 | - Last update : 2014/04/15 14:19 by matthieu@embryo (inserted by vim). | 3 | + Last update : 2015/01/29 18:44 by matthieu@Embryo (inserted by vim). |
4 | ====================================================================================================================== | 4 | ====================================================================================================================== |
5 | Library import: | 5 | Library import: |
6 | read tools/basis.anubis | 6 | read tools/basis.anubis |
anubis_dev/library/tools/iterators.anubis
1 | Author : Matthieu Herrmann | 1 | Author : Matthieu Herrmann |
2 | Creation : 2014/02/10 | 2 | Creation : 2014/02/10 |
3 | - Last update : 2014/09/22 16:39 by matthieu@embryo (inserted by vim). | 3 | + Last update : 2015/03/09 11:33 by matthieu@Embryo (inserted by vim). |
4 | ====================================================================================================================== | 4 | ====================================================================================================================== |
5 | 5 | ||
6 | ====================================================================================================================== | 6 | ====================================================================================================================== |
@@ -181,6 +181,10 @@ public define Iterator(($A,$B)) zip(Iterator($A) it1, Iterator($B) it2). | @@ -181,6 +181,10 @@ public define Iterator(($A,$B)) zip(Iterator($A) it1, Iterator($B) it2). | ||
181 | *** (6) Iterator printing | 181 | *** (6) Iterator printing |
182 | ================================================================================================================== | 182 | ================================================================================================================== |
183 | 183 | ||
184 | + Create a sequential string representation of the iterator with a custom separator and enclosing string only puts | ||
185 | + if the iterator is non-empty. | ||
186 | +public define String to_string(Iterator($A) it, $A->String op, String first, String sep, String last). | ||
187 | + | ||
184 | Create a sequential string representation of the iterator with a custom separator. | 188 | Create a sequential string representation of the iterator with a custom separator. |
185 | public define String to_string(Iterator($A) it, $A->String op, String sep). | 189 | public define String to_string(Iterator($A) it, $A->String op, String sep). |
186 | 190 | ||
@@ -488,6 +492,7 @@ public define Int length(Iterator($A) ita) = length(ita, 0). | @@ -488,6 +492,7 @@ public define Int length(Iterator($A) ita) = length(ita, 0). | ||
488 | *** [7.1] Internal printing definitions | 492 | *** [7.1] Internal printing definitions |
489 | ================================================================================================================ | 493 | ================================================================================================================ |
490 | 494 | ||
495 | + Put the Separators on the following prints | ||
491 | define String to_string2(Iterator($A) it, $A->String op, String sep, String str) = | 496 | define String to_string2(Iterator($A) it, $A->String op, String sep, String str) = |
492 | if get(it) is | 497 | if get(it) is |
493 | { | 498 | { |
@@ -495,6 +500,7 @@ define String to_string2(Iterator($A) it, $A->String op, String sep, String str) | @@ -495,6 +500,7 @@ define String to_string2(Iterator($A) it, $A->String op, String sep, String str) | ||
495 | success(s) then to_string2( next(it), op, sep, str + sep + op(s)) | 500 | success(s) then to_string2( next(it), op, sep, str + sep + op(s)) |
496 | }. | 501 | }. |
497 | 502 | ||
503 | + Do not put the separator on the 'first' print | ||
498 | define String to_string(Iterator($A) it, $A->String op, String sep, String str) = | 504 | define String to_string(Iterator($A) it, $A->String op, String sep, String str) = |
499 | if get(it) is | 505 | if get(it) is |
500 | { | 506 | { |
@@ -502,9 +508,13 @@ define String to_string(Iterator($A) it, $A->String op, String sep, String str) | @@ -502,9 +508,13 @@ define String to_string(Iterator($A) it, $A->String op, String sep, String str) | ||
502 | success(s) then to_string2( next(it), op, sep, str + op(s)) | 508 | success(s) then to_string2( next(it), op, sep, str + op(s)) |
503 | }. | 509 | }. |
504 | 510 | ||
511 | + | ||
505 | *** [7.2] Public printing interface. | 512 | *** [7.2] Public printing interface. |
506 | ================================================================================================================ | 513 | ================================================================================================================ |
507 | 514 | ||
515 | +public define String to_string(Iterator($A) it, $A->String op, String first, String sep, String last) = | ||
516 | + if it is nil then "" else to_string(it, op, sep, first) + last. | ||
517 | + | ||
508 | public define String to_string(Iterator($A) it, $A->String op, String sep) = to_string(it, op, sep, ""). | 518 | public define String to_string(Iterator($A) it, $A->String op, String sep) = to_string(it, op, sep, ""). |
509 | 519 | ||
510 | public define String to_string(Iterator($A) it, $A->String op) = to_string(it, op, ", "). | 520 | public define String to_string(Iterator($A) it, $A->String op) = to_string(it, op, ", "). |