GithubHelp home page GithubHelp logo

fachen2015 / trove Goto Github PK

View Code? Open in Web Editor NEW

This project forked from misberner/trove

0.0 1.0 0.0 4.53 MB

A fork of the Trove library for Java (http://trove.starlight-systems.com/).

License: GNU Lesser General Public License v2.1

Java 99.86% HTML 0.14%

trove's Introduction

   GNU Trove: High performance collections for Java.

Objectives

   The GNU Trove library has two objectives:
    1. Provide "free" (as in "free speech" and "free beer"), fast,
       lightweight implementations of the java.util Collections API.
       These implementations are designed to be pluggable replacements
       for their JDK equivalents.
    2. Whenever possible, provide the same collections support for
       primitive types. This gap in the JDK is often addressed by using
       the "wrapper" classes (java.lang.Integer, java.lang.Float, etc.)
       with Object-based collections. For most applications, however,
       collections which store primitives directly will require less
       space and yield significant performance gains.

Hashtable techniques

   The Trove maps/sets use open addressing instead of the chaining
   approach taken by the JDK hashtables. This eliminates the need to
   create Map.Entry wrappper objects for every item in a table and so
   reduces the O (big-oh) in the performance of the hashtable algorithm.
   The size of the tables used in Trove's maps/sets is always a prime
   number, improving the probability of an optimal distribution of
   entries across the table, and so reducing the likelihood of
   performance-degrading collisions. Trove sets are not backed by maps,
   and so using a THashSet does not result in the allocation of an unused
   "values" array.

Hashing strategies

   Trove's maps/sets support the use of custom hashing strategies,
   allowing you to tune collections based on characteristics of the input
   data. This feature also allows you to define hash functions when it is
   not feasible to override Object.hashCode(). For example, the
   java.lang.String class is final, and its implementation of hashCode()
   takes O(n) time to complete. In some applications, however, it may be
   possible for a custom hashing function to save time by skipping
   portions of the string that are invariant.

   Using java.util.HashMap, it is not possible to use Java language
   arrays as keys. For example, this code:
    char[] foo, bar;
    foo = new char[] {'a','b','c'};
    bar = new char[] {'a','b','c'};
    System.out.println(foo.hashCode() == bar.hashCode() ?
      "equal" : "not equal");
    System.out.println(foo.equals(bar) ? "equal" : "not equal");
    

   produces this output:
    not equal
    not equal
    

   And so an entry stored in a java.util.HashMap with foo as a key could
   not be retrieved with bar, since there is no way to override
   hashCode() or equals() on language array objects.

   In a gnu.trove.map.hash.TCustomHashMap, however, you can implement a
   gnu.trove.strategy.HashingStrategy to enable hashing on arrays:
    class CharArrayStrategy implements HashingStrategy {
        public int computeHashCode(Object o) {
            char[] c = (char[])o;
            // use the shift-add-xor class of string hashing functions
            // cf. Ramakrishna and Zobel,
            //     "Performance in Practice of String Hashing Functions"
            int h = 31; // seed chosen at random
            for (int i = 0; i < c.length; i++) { // could skip invariants
                // L=5, R=2 works well for ASCII input
                h = h ^ ((h << 5) + (h >> 2) + c[i]);
            }
            return h;
        }

        public boolean equals(Object o1, Object o2) {
            char[] c1 = (char[])o1;
            char[] c2 = (char[])o2;
            // could drop this check for fixed-length keys
            if (c1.length != c2.length) {
                return false;
            }
            // could skip invariants
            for (int i = 0, len = c1.length; i < len; i++) {
                if (c1[i] != c2[i]) {
                    return false;
                }
            }
            return true;
        }
    }
    

Iterators in primitive collections

   Trove's primitive mappings include access through Iterators as well
   as procedures and functions. The API documentation on those classes
   contains several examples showing how these can be used effectively
   and explaining why their semantics differ from those of
   java.util.Iterator.

_________________________________________________________________

   Last modified: Sep 9, 2011

trove's People

Contributors

sethp-jive avatar schlosna avatar splatch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.