Friday, February 10, 2012

Trove - high speed regular and primitive collections

/*
 * see: http://trove.starlight-systems.com/
 */
@Grapes(
    @Grab(group='net.sf.trove4j', module='trove4j', version='3.0.2')
)
import gnu.trove.set.*
import gnu.trove.set.hash.*
import gnu.trove.list.*
import gnu.trove.list.array.*
import gnu.trove.list.linked.*
import gnu.trove.map.*
import gnu.trove.map.hash.*

//Most Trove classes start with the letter "T" to indicate that they're part of the Trove library.
THashSet s = new THashSet()
100.times { i ->
  s.add ((i / 2).toInteger())
}
assert s.size() == 50
assert s.contains(0)

TIntArrayList a = new TIntArrayList()
100.times { i ->
  a.add ((i / 3).toInteger())
}
assert a.size() == 100
assert a.get(0) == 0

TIntLinkedList l = new TLinkedList()
100.times { i ->
  l.add ((i / 4).toInteger())
}
assert l.size() == 100
assert l.get(0) == 0

THashMap m = new THashMap()
m['a'] = 1
m.b = 2
assert m.a == 1

No comments:

Post a Comment