Hello everybody,
I was wondering if there is a way to find a key which does not exist in a
map in an efficient way. you can assume that all the keys are integers.
I currently do something like
(defn non-existent-key [mp]
(first (filter (comp not mp) (range
Is there a possibly m
If you have control over the creation of the map, you could use something like
a global counter to provide the next valid key.
You could also use a sorted map and just increment to last (biggest) key in the
map.
Or you could use a random number. If the range is big enough, the probability
of col
This is what I've come up with so far...it should give a bit of an idea of what
I'm using it for:
(defprotocol PSparseVec
(norm [this])
(cnt [this])
(ith-val [this i])
(unit-vec [this])
(assc [this i o]))
(defrecord SparseVec [indices vals]
PSparseVec
(cnt [this] (count indices))
> I've been doing some experimentation with Clojure on various setups of
> Java/JDK 1.7, including the DaVinci Machine enhancements.
Do you find it reasonably stable on OS X?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send
On Thu, May 26, 2011 at 8:19 AM, Andreas Kostler
wrote:
> (let [new-indices (sort (conj indices i))
> new-idx (bin-search new-indices i)
> [chunk1 chunk2] (split-at new-idx vals)]
> (SparseVec. new-indices (into (conj (vec chunk1) o) chunk2))
>
I've used this approach before. It was simple and worked well. Note that assoc
can take multiple keys and vals so you can simplify it to (assoc m k v v k)
instead of nesting the assoc calls. If there's any chance of a collision, you
could be defensive and test for (contains? m k) or (contains?
Hi,
imaging you could do a software project from scratch and Clojure is the main
programming language. What architecture would you choose? Of course it
depends, so here are some requirements and basic conditions:
- Let's assume that we are building a web application for some social
media st
David,
Yes. I am in Nigeria.
Emeka
On Tue, May 24, 2011 at 9:43 AM, David Jagoe wrote:
> Are you in Nigeria?
>
> Anyone else on this list in Africa?
>
>
>
> On Sunday, 22 May 2011, Emeka wrote:
> > Okay.
> > I live in Africa... maybe we should have online meetups for now.
> > Emeka
> >
> > On
Thank you everyone for the solution.
Ron.
On May 25, 6:24 pm, Luc Prefontaine
wrote:
> Use:
>
> (read-string (read-string "[{:a \"blah\" :b 23} {:d 34 :c \"hello\"}]")
>
> I believe your expression is wrong, (:d should be {:d.
>
> Luc P.
>
> On Wed, 25 May 2011 18:04:11 -0700 (PDT)
>
> ron peter
You could use this:
(defn non-existing-key [mp] (inc (reduce max (keys mp
For example:
(non-existing-key {1 "a" 2 "b"}) => 3
--
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
Note that p
On May 25, 7:39 pm, Rob Lachlan wrote:
> I'm curious about this as well, because of the ICFP programming
> contest. The contest organizers are soliciting requests for Debian packages to
> be installed on the contest environment. I don't suppose that this is
> the reason that you're asking?
No, I
Hi guys,
I'm kinda lost as to what's going on here...With clojure-1.2.0
(defn bin-search [v k c]
(loop [l 0
h (dec (count v))]
(if (> l h) false
(let [m (quot (+ l h) 2)
m-v (v m)]
(cond (> m-v k) (recur (inc m) h)
(> k m-v) (recur l
h gets boxed somehow from integer to something else when the recur is executed.
No idea where however. Look at this, it may help:
http://groups.google.com/group/clojure/browse_thread/thread/e4574bbb01155c4d
On Fri, 27 May 2011 09:54:19 +1000
Andreas Kostler wrote:
> Hi guys,
> I'm kinda lost
Thanks Ken,
using this approach brings a ~1000 times speedup :)
(def a (sparse-vec (range 10) (range 10)))
(def b (time (assc-ken a 11 0)))
"Elapsed time: 0.249 msecs"
(def b (time (assc a 11 0)))
"Elapsed time: 252.06 msecs"
Very worthwhile and it's clearer as well.
Cheers
Andr
On Thu, May 26, 2011 at 8:50 PM, Andreas Kostler
wrote:
> Thanks Ken,
> using this approach brings a ~1000 times speedup :)
>
> (def a (sparse-vec (range 10) (range 10)))
>
> (def b (time (assc-ken a 11 0)))
> "Elapsed time: 0.249 msecs"
>
> (def b (time (assc a 11 0)))
> "Elapsed
That explains the good performance. Either way, the implementation is quite a
bit clearer.
I've also compared some operations of sparse-vec vs. plain map.
The inner product is slightly faster for vecs with < 10 elements, then map
takes over.
norm and unit-vector operations are quite in favo
Coercing m to int somehow prevents h from being boxed:
user=> (defn bin-search [v k c]
(loop [l 0
h (dec (count v))]
(if (> l h) false
(let [m (int (quot (+ l h) 2))
m-v (v m)]
(cond (> m-v k) (recur (inc m) h)
(> k m-v) (recur l (dec
I also long for the latest Clojure in Debian.
The current main packager seems to be too busy to responsive.
With discussion at debian-java mail list, I have just uploaded Clojure
1.2.0. Since it is a brand new source version, it will take several
days for FTP Masters to accept it.
If you have com
On Thu, May 26, 2011 at 10:28 PM, Armando Blancas
wrote:
> Coercing m to int somehow prevents h from being boxed:
>
> user=> (defn bin-search [v k c]
> (loop [l 0
> h (dec (count v))]
> (if (> l h) false
> (let [m (int (quot (+ l h) 2))
> m-v (v m)]
> (cond
The question is though, why doesn't this work to begin with and why does it
work on 1.3.0-master-SNAPSHOT...?
Is it broken or am I doing something wrong? :)
Andreas
On 27/05/2011, at 1:28 PM, Ken Wesson wrote:
> On Thu, May 26, 2011 at 10:28 PM, Armando Blancas
> wrote:
>> Coercing m to int so
I compiled a new version of emacs from source and started it up.
clojure-jack-in just worked flawlessly. This is stupid simple! Thanks
for your hard work! It's much appreciated for emacs newcomers like me
(I'm a vim user)!
Thanks again,
J.R. Garcia
On May 24, 6:55 pm, Phil Hagelberg wrote:
> On
On Thu, May 26, 2011 at 11:31 PM, Andreas Kostler
wrote:
> The question is though, why doesn't this work to begin with and why does it
> work on 1.3.0-master-SNAPSHOT...?
> Is it broken or am I doing something wrong? :)
On further investigation, it looks like Clojure considers the type of
(count
Nope it's not broken, in 1.3 numeric computations changed.
Rich wanted to streamline the behavior and gain performance in numeric
computations.
Non floating point values are now all longs except if you cast them explicitly
(java interop needs this),
floats are now all doubles (the widest type of
I don't think yours is going to be anymore efficient than the one I had
initially posted .. In fact it might be slower in majority of the cases..
Thanks,
Sunil.
On Fri, May 27, 2011 at 12:57 AM, Walter van der Laan <
waltervanderl...@gmail.com> wrote:
> You could use this:
> (defn non-existing-ke
24 matches
Mail list logo