Javolution/Trove/Java

Have you created a useful tool? or Do you want to get help building one? This is the right place!
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
Forsaiken
L2j Veteran
L2j Veteran
Posts: 99
Joined: Sun Mar 11, 2007 6:23 pm

Javolution/Trove/Java

Post by Forsaiken »

Hi.

Just wanted to give u some infos about all that FastMap/TIntHashs.

We start with: FastMap
A FastMap is nothing else then an regular HashMap/THashMap, but has a big difference... all entries are LINKED!
Thats also the reason why FastMap iterations are much faster then iterating over an HashMap or using forEach on THashMap.

Whats "setShared()" on FastMap?
This flag does 2 things:
1: The linked entries never loose it`s links to the prev/next entry which results in an "save" iteration while removing/adding values to an map.
2: It will self synchronized when adding/removing values, like "synchronized(map){map.put(key, value);}"
Ofc this synchronisation slows down the FastMap because it must enter the thread monitor when adding/removing values.

Well Trove is not far away form the Java originals (in basics) but as u know it use primitive datatypes as key/value. So far u need to sync every access to the map if u don`t want urgend exceptions or fails. ReentrantReadWriteLock is ur friend again.

When to use Trove, Java, Javolution?

Code: Select all

 using:THashMap<Integer, Object>TIntObjectHashMap<Object>FastMap<Integer, Object>HashMap<Integer, Object> Put (already in map)THashMap: 204%TIntObjectHashMap: 89%FastMap: 198%HashMap: 100% PutIfAbsent (already in map)THashMap: 160%TIntObjectHashMap: 45%FastMap: 100%HashMap: - Get (in map)THashMap: 189%TIntObjectHashMap: 49%FastMap: 137%HashMap: 100% Get (not in map)THashMap: 295%TIntObjectHashMap: 50%FastMap: 139%HashMap: 100% ContainsKey (in map)THashMap: 177%TIntObjectHashMap: 34%FastMap: 136%HashMap: 100% ContainsKey (not in map)THashMap: 292%TIntObjectHashMap: 39%FastMap: 145%HashMap: 100% ContainsValue (in map avg)THashMap: 143%TIntObjectHashMap: 150%FastMap: 57%HashMap: 100% ContainsValue (not in map)THashMap: 123%TIntObjectHashMap: 142%FastMap: 85%HashMap: 100% IterateTHashMap: 92%TIntObjectHashMap: 113%FastMap: 35%HashMap: 100% 
Less = better.
As u can see Trove is ONLY suitable for primitives!
So if u have to iterate more often or do not have an primitive as a key use Javolution.

And now about the lists....
FastList is an LINKED list. If u know the final size of the list or now that u have to add more then > 8 entrys an ArrayList is faster (even with expand)!!! Specialy those cases where u fill into FastList and use toArray()!!!

Hopefully this will help u somehow.
Last edited by Forsaiken on Tue Jan 04, 2011 2:34 am, edited 1 time in total.
http://code.google.com/p/g3d-editor/
Experienced in the following languages/apis/ides: Java using Eclipse/AWT/Swing/NIO/JNI/Jogl, C/C++11/c++14 using QT/MFC/BOOST/STL/VS2012/VS2013/OpenGL/DirectX, Delphi using Borland, .NET/C# using VS2012/VS2013
User avatar
DrHouse
L2j Inner Circle
L2j Inner Circle
Posts: 912
Joined: Mon Jan 22, 2007 12:14 am
Location: Spain

Re: Javolution/Trove/Java

Post by DrHouse »

Thanks :) very interesting
Image

Leadership and management are not talk and talk, but talk and do

Proud of being a part of this project
Phantom2005
Posts: 72
Joined: Wed Jul 06, 2005 4:27 pm
Location: Netherlands

Re: Javolution/Trove/Java

Post by Phantom2005 »

So what you're basically saying is.. change knownlist FastList's to ArrayList?
(since there's a big chance u have to add more than 8 )

Interesting thread btw.
"If 64 bits isn't enough, the next logical step is 128 bits. That's enough to survive Moore's Law until I'm dead, and after that, it's not my problem."
©Jeff Bonwick
VISTALL
Posts: 12
Joined: Sun Mar 14, 2010 2:53 pm
Contact:

Re: Javolution/Trove/Java

Post by VISTALL »

big thx link for my friend :o


If u dont read api docs of javolution http://javolution.org/target/site/apido ... stMap.html

Image

FastMap is use better if too many values(more than 10k) if values size is lower need use HashMap
issle88
Posts: 36
Joined: Sat Apr 01, 2017 2:35 pm

Re: Javolution/Trove/Java

Post by issle88 »

VISTALL wrote:big thx link for my friend :o


If u dont read api docs of javolution http://javolution.org/target/site/apido ... stMap.html

Image

FastMap is use better if too many values(more than 10k) if values size is lower need use HashMap
That depends on the functionallity your data structure is intended to do. Each data structure performs in a different way based on the operation you are performing to it ( insertion, search, removal ).

Here's an example: The SkillsTable. It gets loaded whenever the server gets started or you call //reload skills. But it gets read very often , much more often than it gets inserted. So in that case, a data structure with small search complexity would be preffered over a data structure with small insertion complexity, since in total we got more "reads" than "insertions.
VISTALL
Posts: 12
Joined: Sun Mar 14, 2010 2:53 pm
Contact:

Re: Javolution/Trove/Java

Post by VISTALL »

Issle wrote:
VISTALL wrote:big thx link for my friend :o


If u dont read api docs of javolution http://javolution.org/target/site/apido ... stMap.html

Image

FastMap is use better if too many values(more than 10k) if values size is lower need use HashMap
That depends on the functionallity your data structure is intended to do. Each data structure performs in a different way based on the operation you are performing to it ( insertion, search, removal ).

Here's an example: The SkillsTable. It gets loaded whenever the server gets started or you call //reload skills. But it gets read very often , much more often than it gets inserted. So in that case, a data structure with small search complexity would be preffered over a data structure with small insertion complexity, since in total we got more "reads" than "insertions.
yeah is data is static(put only at start is not really difference), but if is ad L2World and Map of moving characters is use good FastMap
User avatar
MELERIX
L2j Veteran
L2j Veteran
Posts: 6667
Joined: Sat Sep 23, 2006 11:31 pm
Location: Chile
Contact:

Re: Javolution/Trove/Java

Post by MELERIX »

Trove 3.0.0 Final Stable has been released today

Changelog:
--- 3.0.0 ---
  - !!! Major restructuring of classes and packages !!!
    Interfaces have been broken out to allow for alternate implementations.
    The package changes will require code migration, although it should mainly
    consist of simply updating import statements. However, because everything is
    in new packages, both Trove 2.x and Trove 3.x can co-exist in a classpath
    (to hopefully ease the migration burden).
  - Broke out classes that allow custom hashing for performance reasons.
    New collections are:
       - TCustomHashMap
       - TCustomHashSet
       - TObject*CustomHashMap (ex: TObjectIntCustomHashMap)
    IdentityHashingStrategy is available for identity-based hash maps.
  - [ 3152276 ] Add sum() method to T*List
  - [ 3159432 ] THashMap.entrySet().remove() throws on non-Entries
  - [ 3153005 ] fix for null keys in Object maps
  - Benchmarks for comparing different libraries. Currently java.util, Colt,
    Trove 2 and Trove 3.
  - Fixes to serialVersionUID's and where Serializable is marked. For example,
    Serializable has been removed from the interfaces for various collections
    (to better match how it's done in java.util).
  - Many bug fixes, particularly to TLinkedList.
Download link: http://sourceforge.net/projects/trove4j ... p/download
User avatar
MELERIX
L2j Veteran
L2j Veteran
Posts: 6667
Joined: Sat Sep 23, 2006 11:31 pm
Location: Chile
Contact:

Re: Javolution/Trove/Java

Post by MELERIX »

Trove 3.0.1 is now available for downloads. This is mainly a bug fix release with a number of minor features.

Changelog:
--- 3.0.1 ---
Bugs Fixed:
- fix for ClassCastException in equals(T,T) when comparing with REMOVED
- [3408129] Benchmarks don't run correctly
- [3394094] Args to gnu.trove.generator.Generator not basedir-relative
- Re-introduce TLinkableAdapter class
New Features:
- [3412967] Need TMap interface
- .zip and .tgz files now expand into a sub-directory
- Documentation for generator patterns and replicated blocks
- Maven artifact generation now a bit more automatic
Download Link: http://sourceforge.net/projects/trove4j ... p/download
User avatar
MELERIX
L2j Veteran
L2j Veteran
Posts: 6667
Joined: Sat Sep 23, 2006 11:31 pm
Location: Chile
Contact:

Re: Javolution/Trove/Java

Post by MELERIX »

Trove 3.0.2 has been released. This release contains a couple of significant bug fixes and is highly recommended for all 3.x users.

Changelog:
Bug Fixed:
■ [3429703] TIntObjectHashMap losing entry
■ [3431135] ArrayIndexOutOfBoundsException at TIntIntHashMap.keys
■ [3432212] entrySet() does not unwrap in cased of no_entry_value or no_entrykey
■ [3432175] Decorator entrySet() -keySet() impl - Minor problem with the way null keys are unwarped
Download Link: http://sourceforge.net/projects/trove4j ... p/download
User avatar
MELERIX
L2j Veteran
L2j Veteran
Posts: 6667
Joined: Sat Sep 23, 2006 11:31 pm
Location: Chile
Contact:

Re: Javolution/Trove/Java

Post by MELERIX »

Trove 3.0.3 has been released. This release is a minor bugfix release recommended for all users.
Bugs Fixed:
- [3445639] ArrayIndexOutOfBoundsException from TIntHashSet.retainAll
- [3460395] no_entry_value is set always to 0 in map default constructor
Download Link: http://sourceforge.net/projects/trove4j ... ove/3.0.3/
Ahmed
L2j Veteran
L2j Veteran
Posts: 64
Joined: Fri Jan 04, 2008 2:13 pm
Location: USA

Re: Javolution/Trove/Java

Post by Ahmed »

MELERIX wrote:Trove 3.0.3 has been released. This release is a minor bugfix release recommended for all users.
Bugs Fixed:
- [3445639] ArrayIndexOutOfBoundsException from TIntHashSet.retainAll
- [3460395] no_entry_value is set always to 0 in map default constructor
Download Link: http://sourceforge.net/projects/trove4j ... ove/3.0.3/
Anyone using 3.0.3 have any issues? or should we update it in our lib?
Image
User avatar
MELERIX
L2j Veteran
L2j Veteran
Posts: 6667
Joined: Sat Sep 23, 2006 11:31 pm
Location: Chile
Contact:

Re: Javolution/Trove/Java

Post by MELERIX »

3.0.3 give some errors with L2J (you can see them in eclipse), I guess is due some parts of code require update.
Ahmed
L2j Veteran
L2j Veteran
Posts: 64
Joined: Fri Jan 04, 2008 2:13 pm
Location: USA

Re: Javolution/Trove/Java

Post by Ahmed »

MELERIX wrote:3.0.3 give some errors with L2J (you can see them in eclipse), I guess is due some parts of code require update.
Thanks will look into it and keep you posted :)

Trove 3.0.2
values
public V[] values()
  • Returns the values of the map as an array of int values. Changes to the array of values will not be reflected in the map nor vice-versa.

Specified by:
  1. values in interface TIntObjectMap<V>
Returns:
  • the values of the map as an array of int values.
Trove 3.0.3
values
public java.lang.Object[] values()
  • Returns the values of the map as an Object array. Note that the array returned is typed as an Object[] and may not be cast to a more specific type. See #values(V[]) for a version which allows specifically typed arrays. Changes to the array of values will not be reflected in the map nor vice-versa.

Specified by:
  1. values in interface TIntObjectMap<V>
Returns:
  • the values of the map as an array of int values.
Image
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Javolution/Trove/Java

Post by UnAfraid »

They seriously don't have what todo..
Image
Post Reply