diff options
| author | 2021-08-16 23:41:17 +0300 | |
|---|---|---|
| committer | 2021-08-16 23:41:17 +0300 | |
| commit | e2ffca246692c28222394ce4a927cf61a7f16bc6 (patch) | |
| tree | c21b90d96db28bb944d9e5a6f64ca8e5936e6045 /srfi/srfi-125-impl.scm | |
| parent | typos (diff) | |
work
Diffstat (limited to 'srfi/srfi-125-impl.scm')
| -rw-r--r-- | srfi/srfi-125-impl.scm | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/srfi/srfi-125-impl.scm b/srfi/srfi-125-impl.scm new file mode 100644 index 0000000..61863b5 --- /dev/null +++ b/srfi/srfi-125-impl.scm @@ -0,0 +1,160 @@ +(define hash-table-dtd + (let () + + (define (t125:make-hash-table* dtd comparator) + (t125:hash-table comparator)) + + (define (t125:hash-table-set!* dtd table . obj) + (apply t125:hash-table-set! (cons table obj)) + table) + + (define (t125:hash-table-update!* dtd table key updater fail success) + (t125:hash-table-update! table key updater fail success) + table) + + (define (t125:hash-table-update!/default* dtd table key proc default) + (t125:hash-table-update!/default table key proc default) + table) + + (define (t125:hash-table-intern!* dtd table key failure) + (define val (t125:hash-table-intern! table key failure)) + (values table val)) + + (define (t125:hash-table-pop!* dtd table) + (if (t125:hash-table-empty? table) + (error "popped empty dictionary") + (call-with-values + (lambda () (t125:hash-table-pop! table)) + (lambda (key value) (values table key value))))) + + (define (t125:hash-table-delete-all!* dtd table keys) + (for-each + (lambda (key) + (t125:hash-table-delete! table key)) + keys) + table) + + (define (t125:hash-table-map!* dtd proc table) + (t125:hash-table-map! proc table) + table) + + (define (t125:hash-table-filter!* dtd proc table) + (t125:hash-table-prune! + (lambda (key value) + (not (proc key value))) + table) + table) + + (define (t125:hash-table-filter* dtd proc table) + (dict-filter! dtd proc (dict-copy dtd table))) + + (define (t125:hash-table-remove!* dtd proc table) + (t125:hash-table-prune! proc table) + table) + + (define (t125:hash-table-remove* dtd proc table) + (dict-remove! dtd proc (dict-copy dtd table))) + + (define (t125:hash-table-search!* dtd table key fail success) + (define (handle-success value) + (define (update new-key new-value obj) + (unless (eq? new-key key) + (t125:hash-table-delete! table key)) + (t125:hash-table-set! table new-key new-value) + (values table obj)) + (define (remove obj) + (t125:hash-table-delete! table key) + (values table obj)) + (success key value update remove)) + (define (handle-fail) + (define (ignore obj) + (values table obj)) + (define (insert value obj) + (t125:hash-table-set! table key value) + (values table obj)) + (fail insert ignore)) + + (define default (cons #f #f)) + (t125:hash-table-ref table key handle-fail handle-success)) + + (define (t125:hash-table-search* dtd table key fail success) + (t125:hash-table-search!* dtd (dict-copy dtd table) key fail success)) + + (define (t125:hash-table-comparator* dtd table) + (make-comparator (lambda args #t) + (t125:hash-table-equivalence-function table) + #f + (t125:hash-table-hash-function table))) + + (define (t125:hash-table-copy* dtd table) + (t125:hash-table-copy table)) + + (define (t125:hash-table-size* dtd table) + (t125:hash-table-size table)) + + (define (t125:hash-table-for-each* dtd proc table) + (t125:hash-table-for-each proc table)) + + (define (t125:hash-table-keys* dtd table) + (t125:hash-table-keys table)) + + (define (t125:hash-table-values* dtd table) + (t125:hash-table-values table)) + + (define (t125:hash-table-entries* dtd table) + (t125:hash-table-entries table)) + + (define (t125:hash-table-fold* dtd proc knil table) + (t125:hash-table-fold proc knil table)) + + (define (t125:hash-table-map->list* dtd proc table) + (t125:hash-table-map->list proc table)) + + (define (t125:hash-table->alist* dtd table) + (t125:hash-table->alist table)) + + (define (t125:hash-table?* dtd table) + (t125:hash-table? table)) + + (define (t125:hash-table-empty?* dtd table) + (t125:hash-table-empty? table)) + + (define (t125:hash-table-contains?* dtd table key) + (t125:hash-table-contains? table key)) + + (define (t125:hash-table-ref* dtd table key failure success) + (t125:hash-table-ref table key failure success)) + + (define (t125:hash-table-ref/default* dtd table key default) + (t125:hash-table-ref/default table key default)) + + (make-dtd + make-dictionary-index t125:make-hash-table* + dictionary?-index t125:hash-table?* + dict-empty?-index t125:hash-table-empty?* + dict-contains?-index t125:hash-table-contains?* + dict-ref-index t125:hash-table-ref* + dict-ref/default-index t125:hash-table-ref/default* + dict-set!-index t125:hash-table-set!* + dict-delete-all!-index t125:hash-table-delete-all!* + dict-intern!-index t125:hash-table-intern!* + dict-update!-index t125:hash-table-update!* + dict-update/default!-index t125:hash-table-update!/default* + dict-pop!-index t125:hash-table-pop!* + dict-map!-index t125:hash-table-map!* + dict-filter!-index t125:hash-table-filter!* + dict-filter-index t125:hash-table-filter* + dict-remove!-index t125:hash-table-remove!* + dict-remove-index t125:hash-table-remove* + dict-search!-index t125:hash-table-search!* + dict-search-index t125:hash-table-search* + dict-size-index t125:hash-table-size* + dict-for-each-index t125:hash-table-for-each* + dict-keys-index t125:hash-table-keys* + dict-values-index t125:hash-table-values* + dict-entries-index t125:hash-table-entries* + dict-fold-index t125:hash-table-fold* + dict-map->list-index t125:hash-table-map->list* + dict->alist-index t125:hash-table->alist* + dict-comparator-index t125:hash-table-comparator* + dict-copy-index t125:hash-table-copy*))) |
