-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy paththash-table.lisp
76 lines (48 loc) · 2.14 KB
/
thash-table.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
;; -*- lisp -*-
;; This file is part of STMX.
;; Copyright (c) 2013-2016 Massimiliano Ghilardi
;;
;; This library is free software: you can redistribute it and/or
;; modify it under the terms of the Lisp Lesser General Public License
;; (http://opensource.franz.com/preamble.html), known as the LLGPL.
;;
;; This library is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty
;; of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;; See the Lisp Lesser General Public License for more details.
(in-package :stmx.util)
;;;; * support class for THASH-TABLE
(transactional
(defclass thash-pair (ghash-pair)
;; Override inherited slots to make them transactional.
;; Do NOT override the slots that must remain non-transactional.
;; No need to specify :initform, :initarg, :accessor or :type
;; unless we want to override the settings found in superclasses
((key)
(value)
(next))))
;;;; ** Transactional hash table
(transactional
(defclass thash-table (ghash-table)
;; Override inherited slots to make them transactional.
;; Do NOT override the slots that must remain non-transactional.
;; No need to specify :initform, :initarg, :accessor or :type
;; unless we want to override the settings found in superclasses
((vec)
(count))
(:documentation "Transactional hash table.")))
(defmethod initialize-instance :after ((hash thash-table) &rest other-keys)
(declare (ignore other-keys))
(setf (_ hash aref-fun) #'tsvref
(_ hash set-aref-fun) #'set-tsvref)) ;; (setf tsvref) has a defsetf expansion :(
(defmethod ghash/new-pair ((hash thash-table) key value next)
;; Allocate a GHASH-PAIR, initialize it with KEY, VALUE and NEXT and return it.
(declare (ignore hash)
(type (or null thash-pair) next))
(new 'thash-pair :key key :value value :next next))
(defmethod ghash/new-vec ((hash thash-table) capacity)
;; Allocate a new GHASH-VECTOR with length = CAPACITY,
;; initialize all its elements to NIL and return it.
(declare (ignore hash)
(type fixnum capacity))
(simple-tvector capacity :initial-element nil))