aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/sort.neb36
1 files changed, 29 insertions, 7 deletions
diff --git a/libs/sort.neb b/libs/sort.neb
index b8f324b..081a678 100644
--- a/libs/sort.neb
+++ b/libs/sort.neb
@@ -36,19 +36,29 @@
(redef ret (append ret _item_)))
ret)
-(func insert (lst item)
+(func .insert-num (lst item)
(extend-reduce
- (append (take-while lst (< _item_ item)) item)
- (drop-while lst (< _item_ item))))
+ (append (take-while lst (<= _item_ item)) item)
+ (drop-while lst (<= _item_ item))))
-(func insertion-reduce (lst)
- (reduce insert lst (list)))
+(func .insert-string (lst item)
+ (extend-reduce
+ (append (take-while lst (strcmp _item_ item)) item)
+ (drop-while lst (strcmp _item_ item))))
+
+;(func insertion-reduce (lst)
+; (reduce insert lst (list)))
+
+(func insertion-strings (lst)
+ (reduce .insert-string lst (list)))
+(func insertion-nums (lst)
+ (reduce .insert-num lst (list)))
-(func insertion (lst)
+(func insertion-iter (lst)
(def ret (list))
(for-each lst
- (redef ret (insert ret _item_))
+ (redef ret (.insert-num ret _item_))
(print (->string ret)))
ret)
@@ -119,3 +129,15 @@
(print (concat "after: " (->string after)))
(print (concat "consider: " (->string consider))))
(extend (append (quick before) pivot) (quick after))))))
+
+(func strcmp (left :string right :string)
+ (branch
+ ((or
+ (eq? 0 (length left))
+ (eq? 0 (length right)))
+ (<= (length left) (length right)))
+ ((eq? (first-char left) (first-char right))
+ (strcmp (rest-char left) (rest-char right)))
+ (#true
+ (<= (ord (first-char left)) (ord (first-char right))))))
+