;; ;; util-bst-ldict.scm ;; ;; BST-based symbol dictionary. ;; ;; ISC License ;; ;; Copyright 2023 Brmlab, z.s. ;; Dominik Pantůček ;; ;; Permission to use, copy, modify, and/or distribute this software ;; for any purpose with or without fee is hereby granted, provided ;; that the above copyright notice and this permission notice appear ;; in all copies. ;; ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL ;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED ;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE ;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR ;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS ;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, ;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN ;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ;; (declare (unit util-bst-ldict)) (import duck) (module* util-bst-ldict #:doc ("Reimplementation of old list-based symbol dictionary using new BST backend.") ( ldictstring a) (symbol->string b))))) (define (make-ldict . equality?/pairs) (let ((equality? (if (or (null? equality?/pairs) (not (procedure? (car equality?/pairs)))) eq? (car equality?/pairs))) (pairs (if (or (null? equality?/pairs) (procedure? (car equality?/pairs))) '() (car equality?/pairs)))) (let loop ((ld (make-bst 'ldict equality? ldict=? 2) proc)) (index? ((procedure-arity>=? 3) proc))) (bst-map-bst ld (lambda (k v) (let ((r (if both? (if index? (proc k v i) (proc k v)) (proc v)))) (set! i (add1 i)) r))))) (define (ldict-filter pred? ld) (bst-filter ld pred?)) (define (ldict-reduce init proc ld) (bst-reduce ld proc init)) (define ldict-equal? bst-equal?) )