-
Notifications
You must be signed in to change notification settings - Fork 3
/
grain-sets.lisp
44 lines (37 loc) · 1.26 KB
/
grain-sets.lisp
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
#+xcvb (module (:depends-on ("grain-interface")))
(in-package :xcvb)
(defvar *ordered-grains*
(make-array '(0) :adjustable t :fill-pointer 0)
"Array mapping numbers to grains, so we can associate them and
have compact FMIM set representations. Each grain should conversely have a number
mapping back to this array...")
(defmethod grain-ordinal :before ((grain grain))
(unless (slot-boundp grain 'ordinal)
(setf (grain-ordinal grain)
(vector-push-extend grain *ordered-grains*))))
(defun check-grain-ordinal (ordinal)
(check-type ordinal fixnum)
(assert (< ordinal (fill-pointer *ordered-grains*))))
(defun ordinal-grain (ordinal)
(check-grain-ordinal ordinal)
(aref *ordered-grains* ordinal))
#|
(define-interface <grain-map>
(<encoded-key-map>
<map-empty-is-nil>
<map-decons-from-first-key-value-drop>
<map-divide/list-from-divide>
<map-for-each-from-fold-left>
<map-join/list-from-join>
<map-map/2-from-fold-left-lookup-insert-drop>
<map-size-from-fold-left>
<map-update-key-from-lookup-insert-drop>)
()
(:singleton)
(:method base-interface () <fmim>)
(:method encode-key (grain)
(grain-ordinal grain))
(:method decode-key (ordinal)
(ordinal-grain ordinal)))
(defparameter <gm> <grain-map>)
|#