Commit Graph

2744 Commits

Author SHA1 Message Date
ray.j.greenwell c48106695a Ok, Charlie Groves has done a good job convincing me I'm crazy, but I'll
check this in anyway, at least for posterity.

The advantages over the 'CountingMap' (currently in yohoho):
- Faster, because adding to a count doesn't add to a boxed int, nor does
  it hash twice (except on the intial use of a particular key).

The disadvantages:
- More complicated implementation (CountingMap builds upon google
  collections)
- If a non-HashMap is desired, the fact that the underlying map is
  <K, int[]> is exposed.
- When iterating over the entrySet, each entry is a new object
  created solely for your iteration.

So.. yeah. I'll check it in. Maybe I'll blow it away. We should
probably think about how samskivert will move forward- do we want to
depend on google-collect or guava? Do we want to deprecate huge
swaths of this library in preference to those? A lot of what's
in here is a bit outdated, but maintained to support code built
atop it.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2704 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-16 03:00:23 +00:00
ray.j.greenwell 74d5d82704 Buh-bye.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2703 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-15 01:49:15 +00:00
ray.j.greenwell 2a6397ddcb I'm just going to commit these for posterity, but I'll remove them.
Hell, maybe I should remove IntSets.java too.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2702 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-15 01:48:57 +00:00
ray.j.greenwell e0e2f1cf7d AbstractCollection's isEmpty() calls size(). We can often do better:
- Provide an implementation in AbstractIntSet that checks the interator
  for at least one element.
- Override that in ArrayIntSet so that we're just checking our size again.
- Added optimized isEmpty()s for a few of the inner classes in IntSets.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2701 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-14 21:25:52 +00:00
ray.j.greenwell 8f24b4a8b8 Nix redundant cast.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2700 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-13 18:57:22 +00:00
ray.j.greenwell f731c7b406 Nix redundant cast.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2699 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-13 18:53:15 +00:00
ray.j.greenwell 05d562387c Added getProbability(), from Dave Hoover.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2698 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-13 18:34:15 +00:00
ray.j.greenwell eecca9d71b Dur, and now that we don't need the @SuppressWarnings, we don't
need the temporary variable to which it was applied.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2697 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-13 17:53:34 +00:00
ray.j.greenwell 959e953f99 Covariant return types for the win.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2696 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-13 17:50:13 +00:00
ray.j.greenwell 5bf7699dd4 Missed a spot.
Oh baby, look at the @SuppressWarnings and cast removal.
It's all itchy, flakey, and pale under the cast!


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2695 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-13 17:49:25 +00:00
ray.j.greenwell de860c5602 Now that this library is JDK 1.5, let's return the true type from clone().
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2694 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-13 17:44:50 +00:00
samskivert 7480bb2e6c We should be toString-ing right into our StringBuilder and using the specified
open and close boxes for the internal elements of our sequences.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2693 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-11 05:19:38 +00:00
ray.j.greenwell 818e108f99 Nix import.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2692 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-08 22:05:22 +00:00
ray.j.greenwell d2464d9feb JDK 1.5 compatibility.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2691 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-08 22:04:02 +00:00
ray.j.greenwell 503d57d7de I've been messing with IntSets. I won't check in my more esoteric classes
(RangeIntSet, CompleteIntSet & ClumpyArrayIntSet (which both are capable
of holding every int, and not maxing out at Integer.MAX_VALUE size)).
But here's a bunch of useful stuff all wrapped up nicely.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2690 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-08 18:52:36 +00:00
ray.j.greenwell 61609ffcd5 Be more efficient if constructed with an Interable.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2689 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-08 18:47:28 +00:00
ray.j.greenwell 32d01f5651 Broke-out the notification that we've been posted to a shutdown RunQueue
into a method, so that it can be suppressed, etc.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2688 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-06 20:16:52 +00:00
ray.j.greenwell 838d725bb6 Sorry, Pär, you get slurped up into "et al." like me.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2687 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-06 01:01:03 +00:00
ray.j.greenwell ff9798927c Updated copyright dates, and holder. :)
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2686 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-06 00:53:25 +00:00
ray.j.greenwell f57af39108 Drop unneeded import.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2685 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-06 00:31:57 +00:00
ray.j.greenwell 42c7ea0009 This should be more efficient, right?
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2684 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-06 00:31:36 +00:00
ray.j.greenwell ee8f1aab7e Hey, samskivert requires 1.5 now, so let's label our Timer thread.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2683 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-06 00:28:11 +00:00
ray.j.greenwell 99a46d1613 Spell the package name correctly.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2682 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-05 19:02:21 +00:00
ray.j.greenwell 5282228ee9 Move Mapping all the way up to samskivert.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2681 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2010-01-05 00:56:19 +00:00
ray.j.greenwell 1a56333166 Nixed unneeded @SuppressWarnings, from Jamie Doornbos.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2680 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-14 19:27:20 +00:00
ray.j.greenwell deb50bc136 - Behave better at large sizes.
- Don't wig-out trying to grow from a size larger
    than half of Integer.MAX_VALUE.
  - Don't try to add any values once size reaches Integer.MAX_VALUE.
- Fixed the Interator's remove() to behave properly should it be
  called improperly.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2679 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-11 23:39:53 +00:00
ray.j.greenwell 791121ff37 I picked the wrong week to stop sniffing glue.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2678 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-10 22:33:45 +00:00
ray.j.greenwell 84c6cce89a Make get(), containsKey(), and remove() tolerant of non-Integer objects.
Our IntSets now do this, including the keySet returned by this class.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2677 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-10 20:18:17 +00:00
ray.j.greenwell 2d20fd3454 For debugging, an Interval's toString() should be informative.
The RunBuddy posted to a RunQueue will call its Interval's
toString() method. If an Interval is created with a Runnable,
let's call the Runnable's toString().
We could also add a form of create() that takes a String for the name...


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2676 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-10 19:58:35 +00:00
ray.j.greenwell 6819b85c66 I was a bit overzealous in my import removal.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2675 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-08 20:03:18 +00:00
ray.j.greenwell a6d64b1605 Fuckit. Executor all the way.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2674 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-08 19:57:52 +00:00
ray.j.greenwell 2c04b41b66 More Executor preferring.
Maybe I'm just crazy.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2673 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-08 19:04:49 +00:00
ray.j.greenwell 44c1d15c4b Added an Executor adapter class to RunQueue...
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2672 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-08 19:02:32 +00:00
ray.j.greenwell 7fb3c3354c Well, it's called "SerialExecutor", it would be a shame not to implement
the Executor interface.
- Also accept our "receiver" as an Executor, deprecating the old RunQueue
  constructor.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2671 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-07 21:23:18 +00:00
ray.j.greenwell 50862df9c3 Implement java.util.concurrent.Executor.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2670 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-07 21:18:52 +00:00
ray.j.greenwell 197c6fbbf8 Modernization from Dave Hoover.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2669 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-05 01:52:48 +00:00
ray.j.greenwell 6ca4287fb8 Some happiness for Eclipse, apparently, from Dave Hoover.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2668 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-05 01:52:26 +00:00
ray.j.greenwell a600bcae9c Slap on the old @Override; caught by David "David Hoover" Hoover.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2667 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-05 01:23:52 +00:00
ray.j.greenwell 09dbc956e5 Damn.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2666 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-05 00:00:32 +00:00
ray.j.greenwell 9a2a755931 Look ma, less code.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2665 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-05 00:00:18 +00:00
ray.j.greenwell bfe3ef5096 I may fiddle around with this, but here's one that works.
Provide a method for getting a Comparable Comparator in a typesafe way.
I had to change the Comparator to be untyped.
Hopefully this doesn't hork anything. Oh, now I worry...


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2664 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-04 23:59:42 +00:00
ray.j.greenwell 0a5255f421 Superclass now has a method with a nearly identical signature
and we've been caught forging its checks!


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2663 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-04 22:54:22 +00:00
ray.j.greenwell 983279beae Added a binarySearch() that allows a key to be provided that isn't
the same type as our elements, as long as it can compare our element types.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2662 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-04 20:36:13 +00:00
ray.j.greenwell c64d46d0d8 Allow non-Comparable arrays to be searched using a Comparable key.
Is this weird? Maybe. It violates the requirment that the Comparable relation
is transitive, because the "other" object need not even be Comparable.

java.util.Arrays.binarySearch() (added in 1.6) is documented as if it
supports this behavior, but it does not.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2661 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-04 20:35:10 +00:00
ray.j.greenwell 394d37fbc6 Clean up CloneNotSupportedException handling in Cloneables.
Wrap it in an AssertionError.
I looked to Java sources to see what the best practice was:
Sometimes it's ignored, sometimes an InternalError is thrown,
sometimes an AssertionError without the "cause", but sometimes
this pattern, which is clearly the best of those.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2660 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-02 22:48:26 +00:00
ray.j.greenwell e612575c58 Deprecated, a replacement class now exists in the JDK.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2659 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-02 22:44:45 +00:00
ray.j.greenwell 61b3fca73a Rejiggering.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2658 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-02 21:30:17 +00:00
ray.j.greenwell 3658a26e13 - Change of heart: Let's follow the example of EnumSet, which
does not permit null (or, obviously, elements of the wrong type),
  but is gracious about simply returning false if an invalid
  Object is passed to contains() or remove().
- Implement a dumb size().
- toIntArray() impl now deals with oversize IntSets.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2657 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-02 21:29:40 +00:00
ray.j.greenwell 57dffcb1a5 Bugfix: Our entries should compare as equal to any Map.Entry<Integer, K>
with the same key and value.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2656 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-01 21:34:58 +00:00
ray.j.greenwell 00ede903a2 - Bugfix: containsKey() returned false if the associated value was null,
but that's like half the point of the containsKey() method!
- check for shrinkage when values are removed from the keySet, but avoid
  doing iteration-breaking shrinking modifications when remove() is called
  on any of our iterators.
- Slight performance improvement on keySet.remove().
- Other simplifications.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2655 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2009-12-01 21:00:32 +00:00