Skip to content

Commit

Permalink
checkpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
pashields committed Jan 3, 2014
1 parent 20e6399 commit 991d1db
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
8 changes: 6 additions & 2 deletions profiles.clj
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{:dev
{:dependencies [[reiddraper/simple-check "0.5.3"]
[criterium "0.4.2"]]}}
{:global-vars {*warn-on-reflection* true
*assert* true}
:dependencies [[reiddraper/simple-check "0.5.3"]
[criterium "0.4.2"]]}
:provided
{:global-vars {*assert* false}}}
3 changes: 1 addition & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
[org.clojure/core.typed "0.2.19"]
[org.clojure/algo.generic "0.1.1"]]
:dev-dependencies [[reiddraper/simple-check "0.5.3"]]
:core.typed {:check [graf-znak.core]}
:global-vars {*warn-on-reflection* true})
:core.typed {:check [graf-znak.core]})
26 changes: 18 additions & 8 deletions src/graf_znak/core.clj
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
(ns graf-znak.core
(:require [clojure.core.typed :refer :all]
[clojure.algo.generic.functor :refer :all])
[clojure.algo.generic.functor :refer :all]
[clojure.core.reducers :as r])
(:import [java.util.concurrent.atomic AtomicInteger]))

;; Type aliases
(def-alias hook-type (Coll (U Keyword String)))
(def-alias hooks-type (Coll hook-type))
(def-alias hooks-type (Seq hook-type))
(def-alias state-type (Map hook-type
(Ref1 (Map (Coll Any) AtomicInteger))))
(Atom1 (Map (Coll Any) AtomicInteger))))
(def-alias input-type (Map (U Keyword String) Any))

;; Annotations
(ann ^:no-check clojure.core/not-any? (Fn [(Fn [Any -> Boolean]) (Seq Any)
-> Boolean]))
(ann ^:no-check clojure.core/alter (Fn [Any * -> Any]))
Expand All @@ -18,6 +20,11 @@
(Fn [(Fn [x -> y])
(Map k x) ->
(Map k y)])))
(ann ^:no-check clojure.core.reducers/map
(All [x y]
(Fn [(Fn [x -> Any]) (Seq x) -> (Seq Any)])))
(ann ^:no-check clojure.core.reducers/filter
(Fn [(Fn [Any -> Boolean]) (Seq Any) -> (Seq Any)]))

(defn> process-hook
"Processes a single input for a single hook"
Expand All @@ -27,7 +34,7 @@
group (map #(get val %) hook)]
(assert (not (nil? groups)))
(when (not-any? nil? group)
(if (nil? (get @groups group))
(if (not (contains? @groups group))
(dosync
(alter groups assoc group (AtomicInteger. 1)))
(let [^AtomicInteger counter (get @groups group)]
Expand All @@ -39,9 +46,12 @@
:- Number
[hooks :- hooks-type state :- state-type val :- input-type]
(count
(remove nil?
(for> :- Any [hook :- hook-type hooks]
(process-hook state hook val)))))
(into [] (r/filter (fn> :- Boolean
[x :- Any]
(not (nil? x)))
(r/map (fn> :- Any
[hook :- hook-type]
(process-hook state hook val)) hooks)))))

(defn> int-value
:- Int
Expand Down Expand Up @@ -69,7 +79,7 @@
"Generates a new net."
:- net-type
[hooks :- hooks-type]
(let [state (zipmap hooks (repeatedly #(ref (hook-state-factory))))]
(let [state (zipmap hooks (repeatedly #(atom (hook-state-factory))))]
{:send (partial process hooks state)
:check (partial check-hook state)}))

Expand Down

0 comments on commit 991d1db

Please sign in to comment.