File: hash-table.thb

package info (click to toggle)
theme-d 7.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,036 kB
  • sloc: lisp: 9,625; sh: 5,321; makefile: 715; ansic: 477
file content (57 lines) | stat: -rw-r--r-- 1,949 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;; -*-theme-*-

;; Copyright (C) 2015  Tommi Höynälänmaa
;; Distributed under GNU Lesser General Public License version 3,
;; see file doc/LGPL-3.

(define-body (examples hash-table)


  (import (standard-library list-utilities))

  
  (define-param-method make-hash-table (%key %value)
		       (((hash (:procedure (%key <integer>) <integer> pure))
			 (eq-pred? (:procedure (%key %key) <boolean> pure))
			 (i-size <integer>)
			 (dummy %value))
			(:hash-table %key %value) pure)
    (let ((v-l (make-mutable-vector
		(:uniform-list (:pair %key (:singleton %value)))
		i-size
		null)))
      (create (:hash-table %key %value) v-l i-size hash eq-pred?)))


  (define-static-param-virtual-method gen-assoc (%key %value)
    (((al (:hash-table %key %value)) (obj-key %key))
     (:maybe %value)
     pure)
    (let* ((i-index ((field-ref al 'hash) obj-key (field-ref al 'i-size)))
	   (l-assoc (mutable-vector-ref (field-ref al 'v-l-contents) i-index))
	   (obj-assoc (assoc-general obj-key l-assoc
				     null (field-ref al 'eq-pred?))))
      (if (not-null? obj-assoc)
	  (let ((obj1 (cast (:pair %key (:singleton %value)) obj-assoc)))
	    (singleton-get-element (cdr obj1)))
	  null)))


  (define-static-param-virtual-method gen-assoc-set! (%key %value)
    (((al (:hash-table %key %value))
      (obj-key %key)
      (obj-value %value))
     <none>
     nonpure)
    (let* ((i-index ((field-ref al 'hash) obj-key (field-ref al 'i-size)))
	   (v-l-contents (field-ref al 'v-l-contents))
	   (l-assoc (mutable-vector-ref v-l-contents i-index))
	   (obj-assoc (assoc-general obj-key l-assoc
				     null (field-ref al 'eq-pred?))))
      (if (not-null? obj-assoc)
	  (let ((obj1 (cast (:pair %key (:singleton %value)) obj-assoc)))
	    (singleton-set-element! (cdr obj1) obj-value))
	  (let* ((sgt (make-singleton obj-value))
		 (binding (cons obj-key sgt)))
	    (mutable-vector-set! v-l-contents i-index
				 (cons binding l-assoc)))))))