> ;; I defined my own access method so that an accessor is not required,
> ;; however then you need to type hint which makes it too clumsy
> ;; performs very similar to an accessor, in theory slightly faster

Actually there is a very simple way to make "by index" quite usable
without user type hints:

core.clj:
(defn get-field
  "Accesses a struct-map field by index instead of name or accessor"
  [#^clojure.lang.PersistentStructMap s #^Integer index]
  (.access s index))

PersistentStructMap.java:
public Object access(int i) throws Exception{
      return vals[i];
}


user=> (time (reduce (fn [n y] (+ n (get-field y 0))) 0 x))
"Elapsed time: 45.038806 msecs"
4999950000
user=> (time (reduce (fn [n y] (+ n (get-field y 0))) 0 x))
"Elapsed time: 51.727498 msecs"
4999950000
user=> (time (reduce (fn [n y] (+ n (get-field y 0))) 0 x))
"Elapsed time: 50.091357 msecs"
4999950000
user=> (time (reduce (fn [n y] (+ n (get-field y 0))) 0 x))
"Elapsed time: 51.299742 msecs"
4999950000
user=> (time (reduce (fn [n y] (+ n (get-field y 0))) 0 x))
"Elapsed time: 51.106905 msecs"
4999950000

Just thought I'd mention it as it might be a preferable form over
accessors to some people (perhaps only myself *chuckle*).


Regards,
Tim.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to