Zetawar / zetawar

Zetawar is a turn based tactical strategy game implemented in 100% ClojureScript.
MIT License
169 stars 14 forks source link

Discussion: Find-by vs e-by-av #51

Open Conaws opened 7 years ago

Conaws commented 7 years ago

I'm curious whether this

(defn e-by-av [db a v]
  (-> (d/datoms db :avet a v) first :e))

Might in many cases be more efficient than this, (even if adjusted to make use of ssolo etc, and why you wouldn't want to do a straight datom search in these cases

(defn find-by
  "Returns the unique entity identified by either attr (for singleton
  entities) or attr and val."
  ([db attr]
   (qe '[:find ?e
         :in $ ?attr
         :where [?e ?attr]]
       db attr))
  ([db attr val]
   (qe '[:find ?e
         :in $ ?attr ?val
         :where [?e ?attr ?val]]
       db attr val)))
djwhitt commented 7 years ago

I suspect e-by-av would be more efficient. When I added find-by I wasn't as familiar with the raw datom access functions.