GitHub PullRequestReviewCommentEvent at 2014-03-16 22:12:27
Repository: 500lines
Actor: Inaimathi
Payload: {"comment":{"url":"https://api.github.com/repos/aosabook/500lines/pulls/comments/10642132","id":10642132,"diff_hunk":"@@ -0,0 +1,297 @@\n+(ns core.fdb\n+  [:require [clojure.set :as CS :only (union difference )]])\n+\n+;; -- EAVT enty-id -> entity {:attrs -> {attr-name -> attr {:value -> the-value}}}\n+;; -- VAET  structed like this:  {REFed-ent-id -> {attrName -> #{REFing-elems-ids}}}\n+;;         this basically provides this info: for each entity that is REFFed by others (V), separated by the names of the attribute used for reffing (A), hold the set of the ids of the REFing (E), all this at a given time (T)\n+;;         can be used to know who REFs a specific entity\n+;; -- AVET  structed like this:  {attrName-> {attr-val -> #{holding-elems-ids}}}\n+;;         this basically provides this info: for each attributeName (A) that we chose to index, separated by the values of the attribute  (V), hold the set of the ids of the hold thes attributes (E), all this at a given time (T)\n+;;         can be used to know who are the entities that have a specific attribute with a specific value\n+;; -- EVAT structed like this: {ent-id -> {attr-val -> #{attr-names}}}\n+;;         this provides the info - for a given ent-id (E) and specificed value (V), what are the attributes that have a specific name (A) at a given time (T). Other way to understand\n+;;         this index is that it answers the question of  how a specific entity is related to a specific value.\n+(defrecord Database [timestamped top-id curr-time])\n+(defrecord Indices [EAVT VAET AVET EVAT])\n+(defrecord Entity [id attrs])\n+(defrecord Attr [name value ts prev-ts])\n+\n+(defn make-db \"Create an empty database\" []\n+  (atom (Database. [(Indices. {} {} {} {})] 0 0)))\n+\n+(defn make-entity \"creates an entity, if id is not supplied, a running id is assigned to the entity\"\n+  ([] (make-entity :db/no-id-yet ))\n+  ([id] (Entity.  id {})))\n+\n+(defn make-attr\n+  \"creation of an attribute. The name, value and type of an attribute are mandatory arguments, further arguments can be passed as named arguguments.\n+   The type of the attribute may be either :string, :number, :boolean or :db/ref . If the type is :db/ref, the value is an id of another entity and indexing of backpointing is maintained.\n+  The named arguments are as follows:\n+  :indexed - a boolean, can be either true or false - marks whether this attribute should be indexed. By defaults attributes are not inexed.\n+  :cardinality - the cardinality of an attribute, can be either:\n+                     :db/single - which means that this attribute can be a single value at any given time (this is the default cardinality)\n+                     :db/multiple - which means that this attribute is actually a set of values. In this case updates of this attribute may be one of the following (NOTE that all these operations accept a set as argument):\n+                                          :db/add - adds a set of values to the currently existing set of values\n+                                          :db/reset-to - resets the value of this attribute to be the given set of values\n+                                          :db/remove - removes the given set of values from the attribute's current set of values\"\n+  ([name value type ; these ones are required\n+      & {:keys [indexed cardinality] :or {indexed false cardinality :db/single}} ]\n+   (with-meta (Attr. name value -1 -1) {:type type :indexed indexed :cardinality cardinality} )))\n+\n+(defn collify [x] (if (coll? x) x [x]))\n+\n+(defn- single? [attr]\n+  (= :db/single (:cardinality (meta attr))))\n+\n+(defn- indexed? [attr]\n+  (:indexed (meta attr)))\n+\n+(defn- ref? [attr]\n+  (= :db/ref (:type (meta attr))))\n+\n+(defn entity-at \"the entity with the given ent-id at the given time (defualts to the latest time)\"\n+  ([db ent-id ts] (get-in db [:timestamped ts :EAVT ent-id]))\n+                      ([db ent-id] (entity-at db ent-id (:curr-time db))) )\n+\n+(defn attr-at\n+  \"The attribute of an entity at a given time (defaults to recent time)\"\n+  ([db ent-id attr-name] (attr-at db ent-id attr-name (:curr-time db)))\n+  ([db ent-id attr-name ts]\n+   (let [indices ((:timestamped db) ts)]  (get-in indices [:EAVT ent-id :attrs attr-name]))))\n+\n+(defn value-of-at\n+  \"value of a datom at a given time, if no time is provided, we default to the most recent value\"\n+  ([db ent-id attr-name]  (:value (attr-at db ent-id attr-name)))\n+  ([db ent-id attr-name ts] (:value (attr-at db ent-id attr-name ts))))\n+\n+(defn- update-attr-value\n+  \"updating the attribute value based on the kind of the operation, the cardinality defined for this attribute and the given value\"\n+  [attr value operation]\n+  (cond\n+      (single? attr)    (assoc attr :value #{value})\n+   ; now we're talking about an attribute of multiple values\n+      (= :db/reset-to operation)  (assoc attr :value value)\n+      (= :db/add operation)        (assoc attr :value (CS/union (:value attr)  value))\n+      (= :db/remove operation)  (assoc attr :value (CS/difference (:value attr) value))))\n+\n+(defn add-attr\n+  \"adds an attribute to an entity\"\n+  [ent attr]\n+  (let [attr-id (keyword (:name attr))]\n+     (assoc-in ent [:attrs attr-id] attr)))\n+\n+(defn- ave [ent-id attr vl] [attr vl ent-id] )\n+(defn- vae [ent-id attr vl] [vl attr ent-id] )\n+(defn- eva [ent-id attr vl] [ent-id vl attr] )\n+\n+(defn- next-ts [db]\n+  \"returns the next timestamp of the given database\"\n+  (inc (:curr-time db)))\n+\n+(defn- next-id\n+  \"returns a pair composed of the id to use for the given entity and the next free running id in the database\"\n+  [db ent]\n+  (let [top-id (:top-id db)\n+          ent-id (:id ent)\n+          inceased-id (inc top-id)","path":"functionalDB/src/core/fdb.clj","position":96,"original_position":96,"commit_id":"735ca11e73d87f6723b3f47aa1ba101ed4138c71","original_commit_id":"735ca11e73d87f6723b3f47aa1ba101ed4138c71","user":{"login":"Inaimathi","id":218377,"avatar_url":"https://gravatar.com/avatar/b1a747d0a7e3450408e0f07adba49111?d=https%3A%2F%2Fidenticons.github.com%2F1a36d1b7644aaccc53661a23f389f386.png&r=x","gravatar_id":"b1a747d0a7e3450408e0f07adba49111","url":"https://api.github.com/users/Inaimathi","html_url":"https://github.com/Inaimathi","followers_url":"https://api.github.com/users/Inaimathi/followers","following_url":"https://api.github.com/users/Inaimathi/following{/other_user}","gists_url":"https://api.github.com/users/Inaimathi/gists{/gist_id}","starred_url":"https://api.github.com/users/Inaimathi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Inaimathi/subscriptions","organizations_url":"https://api.github.com/users/Inaimathi/orgs","repos_url":"https://api.github.com/users/Inaimathi/repos","events_url":"https://api.github.com/users/Inaimathi/events{/privacy}","received_events_url":"https://api.github.com/users/Inaimathi/received_events","type":"User","site_admin":false},"body":"More odd indentation","created_at":"2014-03-16T22:12:27Z","updated_at":"2014-03-16T22:12:27Z","html_url":"https://github.com/aosabook/500lines/pull/27#discussion_r10642132","pull_request_url":"https://api.github.com/repos/aosabook/500lines/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/aosabook/500lines/pulls/comments/10642132"},"html":{"href":"https://github.com/aosabook/500lines/pull/27#discussion_r10642132"},"pull_request":{"href":"https://api.github.com/repos/aosabook/500lines/pulls/27"}}}}