Permalink
Browse files

Fix bin-insert! so it properly updates min/max

  • Loading branch information...
1 parent 2d89976 commit 1d839d0a6a22a97cd41a136a37088cc1970b4811 @ashenfad ashenfad committed Mar 12, 2013
Showing with 17 additions and 10 deletions.
  1. +2 −2 README.md
  2. +1 −1 project.clj
  3. +7 −7 src/java/com/bigml/histogram/Histogram.java
  4. +7 −0 test/bigml/histogram/test/core.clj
View
@@ -25,7 +25,7 @@ interface, but Java developers can find documented methods in
For [Leiningen](https://github.com/technomancy/leiningen):
```clojure
-[bigml/histogram "3.2.0"]
+[bigml/histogram "3.2.1"]
```
For [Maven](http://maven.apache.org/):
@@ -38,7 +38,7 @@ For [Maven](http://maven.apache.org/):
<dependency>
<groupId>bigml</groupId>
<artifactId>histogram</artifactId>
- <version>3.2.0</version>
+ <version>3.2.1</version>
</dependency>
```
View
@@ -1,5 +1,5 @@
-(defproject bigml/histogram "3.2.0"
+(defproject bigml/histogram "3.2.1"
:description "Streaming histograms for Clojure/Java"
:min-lein-version "2.0.0"
:url "https://github.com/bigmlcom/histogram"
@@ -221,6 +221,13 @@ public Histogram(int maxBins) {
* @param bin the new bin
*/
public Histogram<T> insertBin(Bin<T> bin) {
+ if (_minimum == null || _minimum > bin.getMean()) {
+ _minimum = bin.getMean();
+ }
+ if (_maximum == null || _maximum < bin.getMean()) {
+ _maximum = bin.getMean();
+ }
+
clearCacheMaps();
_bins.insert(bin);
_bins.merge();
@@ -641,13 +648,6 @@ private void processPointTarget(Double point, Target target) {
if (point == null) {
insertMissing(1, (T) target);
} else {
- if (_minimum == null || _minimum > point) {
- _minimum = point;
- }
- if (_maximum == null || _maximum < point) {
- _maximum = point;
- }
-
insertBin(new Bin(point, 1, target));
}
}
@@ -332,3 +332,10 @@
(extended-sum tree 0.33)))
(is (= (extended-sum array 0.66)
(extended-sum tree 0.66)))))
+
+(deftest bin-inserts
+ (let [hist (-> (create)
+ (insert-bin! {:mean 1 :count 1})
+ (insert-bin! {:mean 3 :count 1}))]
+ (is (== 1 (minimum hist)))
+ (is (== 3 (maximum hist)))))

0 comments on commit 1d839d0

Please sign in to comment.