Commits

Michele Bini committed 146b917

MIT-style licensing terms; rename list::fold_left and list::fold_right to list::fold_forward and list::fold_backward

Comments (0)

Files changed (4)

 # Copyright (c) 2012 Michele Bini
 
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the version 3 of the GNU General Public License
-# as published by the Free Software Foundation.
-
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
 
 ALL=test
 all: $(ALL)
 This implementation is based on finger trees of plain, always balanced
 binary trees; to this effect the finger structure has been modified to
 allow easy assembling and disassembling of trees, by intermixing trees
-with items.  This should reduce code size and improve performance, in
-addition to remove the need for additional rebalancing steps.
+with items.  This should improve performance, and reduces code size by
+remove the need for additional rebalancing steps.
 
 
 * Copyright
 
 Copyright (c) 2012 Michele Bini <michele.bini@gmail.com>
 
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
 
 # Copyright (c) 2012 Michele Bini
 
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
 
 # Requires: standard
 
 	Finger(X) = List((X, Height, tree::Tree(X)));
 
 	# These operations are not meant for exporting, but internally used by the to_list function
-	fun fold_on_left_finger f i (t:Finger(X))   = list::fold_right (fn ((i, h, t), b) = tree::fold_right f (f(i, b)) t) i t;
-	fun fold_on_right_finger f i (t:Finger(X))  = list::fold_left (fn ((i, h, t), b) = tree::fold_right f (f(i, b)) t) i t;
+	fun fold_on_left_finger f i (t:Finger(X))   = list::fold_backward (fn ((i, h, t), b) = tree::fold_right f (f(i, b)) t) i t;
+	fun fold_on_right_finger f i (t:Finger(X))  = list::fold_forward  (fn ((i, h, t), b) = tree::fold_right f (f(i, b)) t) i t;
 
 	empty = NIL;
 
 
 
     fun main' args = {
-	if FALSE
+	if TRUE
+	    my q = deq::empty_queue;
+	    q = fold_forward (fn (a, b) = deq::push(b, a)) q (explode("0123456789abcdefghijklmnopqrstuvwxyz"));
+	    printf "%s\n" (string::implode(deq::to_list(q)));
+	fi;
+	if TRUE
 	    my q = deq::empty_queue;	
-	    q = fold_left (fn (a, b) = deq::push(b, a)) q (explode("0123456789abcdefghijklmnopqrstuvwxyz"));
+	    q = fold_forward (fn (a, b) = deq::push(b, a)) q (explode("0123456789abcdefghijklmnopqrstuvwxyz"));
 	    # deq::debug_print(q);
 	    my (q, c) = deq::pull(q);
 	    printf "Pulled: %c\n" (the c);
 	fi;
 	if FALSE
 	    my q = deq::empty_queue;	
-	    q = fold_left (fn (a, b) = deq::push(b, a)) q (explode("0123456789abcdefghijklmnopqrstuvwxyz"));
+	    q = fold_forward (fn (a, b) = deq::push(b, a)) q (explode("0123456789abcdefghijklmnopqrstuvwxyz"));
 	    # deq::debug_print(q);
 	    for (q = q; !(deq::queue_is_empty(q)); q = q) {
 		my (q, item) = deq::unpush(q);
 	fi;
 	if FALSE
 	    my q = deq::empty_queue;	
-	    q = fold_left (fn (a, b) = deq::push(b, a)) q (explode("The quick brown fox jumps over the lazy dog."));
+	    q = fold_forward (fn (a, b) = deq::push(b, a)) q (explode("The quick brown fox jumps over the lazy dog."));
 	    # deq::debug_print(q);
 	    for (q = q; !(deq::queue_is_empty(q)); q = q) {
 		my (q, item) = deq::pull(q);
 	fi;
 	if TRUE
 	    my q = deq::empty_queue;	
-	    q = fold_left (fn (a, b) = deq::unpull(b, a)) q (explode("The quick brown fox jumps over the lazy dog."));
+	    q = fold_forward (fn (a, b) = deq::unpull(b, a)) q (explode("The quick brown fox jumps over the lazy dog."));
 	    # deq::debug_print(q);
 	    for (q = q; !(deq::queue_is_empty(q)); q = q) {
 		my (q, item) = deq::unpush(q);
 	fi;
 	if FALSE
 	    my q = deq::empty_queue;	
-	    q = fold_left (fn (a, b) = deq::push(b, a)) q (explode("The quick brown fox jumps over the lazy dog."));
+	    q = fold_forward (fn (a, b) = deq::push(b, a)) q (explode("The quick brown fox jumps over the lazy dog."));
 	    # deq::debug_print(q);
 	    my (q, x) = deq::unpush(q);
 	    my (q, x) = deq::unpush(q);