aa
Util.java
Go to the documentation of this file.
1 package com.cliffc.aa.util;
2 
3 import java.util.concurrent.ConcurrentMap;
4 
5 public class Util {
6  public static int find( int[] es, int e ) {
7  for( int i=0; i<es.length; i++ ) if( es[i]==e ) return i;
8  return -1;
9  }
10  public static <E> int find( E[] es, E e ) {
11  for( int i=0; i<es.length; i++ ) if( es[i]==e ) return i;
12  return -1;
13  }
14 
15  // String-equals, with expected interned strings
16  public static boolean eq( String s0, String s1 ) {
17  if( s0==s1 ) return true;
18  if( s0==null || s1==null ) return false;
19  assert !s0.equals(s1) : "Not interned: "+s0;
20  return false;
21  }
22 
23  // Call per every put
24  public static void hash_quality_check_per(ConcurrentMap map) {
25  if( (map.size() & ((1L<<16)-1)) == 0 ) // Reports every 2^16 == 65536 puts
26  hash_quality_check(map);
27  }
28  // Call for a report
29  public static void hash_quality_check(ConcurrentMap map) {
31  for( Object k : map.keySet() ) {
32  int hash = k.hashCode();
33  Integer ii = hashs.get(hash);
34  hashs.put(hash,ii==null ? 1 : ii+1);
35  }
36  int[] hist = new int[16];
37  int maxval=0;
38  long maxkey=-1;
39  for( long l : hashs.keySet() ) {
40  int reps = hashs.get(l);
41  if( reps > maxval ) { maxval=reps; maxkey=l; }
42  if( reps < hist.length ) hist[reps]++;
43  else System.out.println("hash "+l+" repeats "+reps);
44  }
45  for( int i=0; i<hist.length; i++ )
46  if( hist[i] > 0 )
47  System.out.println("Number of hashes with "+i+" repeats: "+hist[i]);
48  System.out.println("Max repeat key "+maxkey+" repeats: "+maxval);
49  }
50 }
com.cliffc.aa.util.Util.find
static int find(int[] es, int e)
Definition: Util.java:6
com.cliffc.aa.util.Util.eq
static boolean eq(String s0, String s1)
Definition: Util.java:16
com.cliffc.aa.util.NonBlockingHashMapLong.keySet
Set< Long > keySet()
Returns a Set view of the keys contained in this map; with care the keys may be iterated over without...
Definition: NonBlockingHashMapLong.java:1168
com.cliffc.aa.util.NonBlockingHashMapLong.get
final TypeV get(long key)
Returns the value to which the specified key is mapped, or.
Definition: NonBlockingHashMapLong.java:368
com.cliffc.aa.util.Util.find
static< E > int find(E[] es, E e)
Definition: Util.java:10
com.cliffc.aa.util.Util
Definition: Util.java:5
com.cliffc.aa.util.Util.hash_quality_check_per
static void hash_quality_check_per(ConcurrentMap map)
Definition: Util.java:24
com.cliffc.aa.util.Util.hash_quality_check
static void hash_quality_check(ConcurrentMap map)
Definition: Util.java:29
com.cliffc.aa.util.NonBlockingHashMapLong
A lock-free alternate implementation of java.util.concurrent.ConcurrentHashMap with primitive long ke...
Definition: NonBlockingHashMapLong.java:91
com.cliffc.aa.util.NonBlockingHashMapLong.put
TypeV put(long key, TypeV val)
Maps the specified key to the specified value in the table.
Definition: NonBlockingHashMapLong.java:278