Commit b9578eb Paula Gearon
committed
1 parent 8524277 commit b9578eb Copy full SHA for b9578eb
File tree 1 file changed +21
-11
lines changed
1 file changed +21
-11
lines changed Original file line number Diff line number Diff line change 39
39
#?(:clj
40
40
(deftype InternalNode [^long id]
41
41
Object
42
- (toString [_] (str " #a/n \" " id " \" " ))
42
+ (toString [_] (str " #a/n[ " id " ] " ))
43
43
(equals [_ o] (and (instance? InternalNode o) (= id (.id ^InternalNode o))))
44
44
(hashCode [_] (hash id))
45
45
IdCheck
48
48
:cljs
49
49
(deftype InternalNode [^long id]
50
50
Object
51
- (toString [_] (str " #a/n \" " id " \" " ))
51
+ (toString [_] (str " #a/n[ " id " ] " ))
52
52
53
53
IEquiv
54
54
(-equiv [_ o] (and (instance? InternalNode o) (= id (.-id o))))
64
64
65
65
#?(:clj
66
66
(defmethod clojure.core /print-method InternalNode [^InternalNode o ^Writer w]
67
- (.write w " #a/n \" " )
67
+ (.write w " #a/n[ " )
68
68
(.write w (str (.id o)))
69
- (.write w " \" " )))
70
-
71
- (defn node-read
72
- " Reads a node from a string"
73
- [s]
74
- (InternalNode.
75
- #?(:clj (Long/parseLong s)
76
- :cljs (long s))))
69
+ (.write w " ]" )))
70
+
71
+ (defprotocol NodeData
72
+ (node-read [data] " Reads an internal node out of data" ))
73
+
74
+ #?(:clj
75
+ (extend-protocol NodeData
76
+ String
77
+ (node-read [s] (InternalNode. (Long/parseLong s)))
78
+ clojure.lang.Indexed
79
+ (node-read [v] (InternalNode. (nth v 0 ))))
80
+
81
+ :cljs
82
+ (extend-protocol NodeData
83
+ string
84
+ (node-read [s] (InternalNode. (long s)))
85
+ PersistentVector
86
+ (node-read [v] (InternalNode. (nth v 0 )))))
77
87
78
88
; ; can set this at a Clojure repl:
79
89
; ; (set! *data-readers* graph/node-reader)
You can’t perform that action at this time.
0 commit comments