-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
57 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(ns graf-znak.atom-storage | ||
(:require [clojure.core.typed :refer :all] | ||
[graf-znak.hook-storage :refer :all])) | ||
|
||
(defn> safe-update | ||
:- (Map (Coll Any) Number) | ||
[coll :- (Map (Coll Any) Number) k :- (Coll Any)] | ||
(let [new-val (inc (get coll k 0))] | ||
(assoc coll k new-val))) | ||
|
||
(ann-datatype AtomStorage [storage :- (Atom1 (Map (Coll Any) Number))]) | ||
(deftype AtomStorage [storage] | ||
HookStorage | ||
(inc-hook | ||
[this group] | ||
(swap! storage safe-update group)) | ||
(get-groups | ||
[this] | ||
@storage)) | ||
|
||
(defn> factory | ||
:- AtomStorage | ||
[] | ||
(let [base {}] | ||
(AtomStorage. (atom (ann-form base (Map (Coll Any) Number)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(ns graf-znak.hook-storage | ||
(:require [clojure.core.typed :refer :all])) | ||
|
||
(ann-protocol HookStorage | ||
inc-hook [HookStorage (Coll Any) -> Any] | ||
get-groups [HookStorage -> (Map (Coll Any) Number)]) | ||
(defprotocol> HookStorage | ||
(inc-hook | ||
[storage group] | ||
"Increment or initialize the count for a given group") | ||
(get-groups | ||
[storage] | ||
"Retrieves all known groups and their counts")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters