@Override public void closeLocal() { if( _gatherRows ) PASS1TMP.put(_uniq,this); }
/** Copies all of the mappings from the specified map to this one, replacing * any existing mappings. * @param m mappings to be stored in this map */ @Override public void putAll(Map<? extends TypeK, ? extends TypeV> m) { for (Map.Entry<? extends TypeK, ? extends TypeV> e : m.entrySet()) put(e.getKey(), e.getValue()); }
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); // Read nothing initialize(MIN_SIZE); for(;;) { final TypeK K = (TypeK) s.readObject(); final TypeV V = (TypeV) s.readObject(); if( K == null ) break; put(K,V); // Insert with an offical put } }
synchronized static private int install( String className, int id ) { Paxos.lockCloud(); if( id == -1 ) id = IDS++; // Leader will get an ID under lock MAP.put(className,id); // No race on insert, since under lock // Expand lists to handle new ID, as needed if( id >= CLAZZES.length ) CLAZZES = Arrays.copyOf(CLAZZES,Math.max(CLAZZES.length<<1,id+1)); if( id >= GOLD .length ) GOLD = Arrays.copyOf(GOLD ,Math.max(CLAZZES.length<<1,id+1)); CLAZZES[id] = className; return id; }
private int nextInstanceCounter(String algoName, NonBlockingHashMap<String, Integer> instanceCounters) { synchronized (instanceCounters) { int instanceNum = 1; if (instanceCounters.containsKey(algoName)) instanceNum = instanceCounters.get(algoName) + 1; instanceCounters.put(algoName, instanceNum); return instanceNum; } }
public ValueString [] computeColumnDomain(){ if( isKilled() ) return null; ValueString vs[] = _map.keySet().toArray(new ValueString[_map.size()]); Arrays.sort(vs); // Alpha sort to be nice for( int j = 0; j < vs.length; ++j ) _map.put(vs[j], j); // Renumber in the map return vs; }
@Override public GroupTask read( AutoBuffer ab ) { super.read(ab); int len = ab.get4(); if( len == 0 ) return this; _grp2val= new NonBlockingHashMap<Group,Double>(); for( int i=0; i<len; i++ ) _grp2val.put(ab.get(Group.class),ab.get8d()); return this; } @Override public void copyOver( Freezable dt ) {
/** * Creates a shallow copy of this hashtable. All the structure of the * hashtable itself is copied, but the keys and values are not cloned. * This is a relatively expensive operation. * * @return a clone of the hashtable. */ @Override public Object clone() { try { // Must clone, to get the class right; NBHM might have been // extended so it would be wrong to just make a new NBHM. NonBlockingHashMap<TypeK,TypeV> t = (NonBlockingHashMap<TypeK,TypeV>) super.clone(); // But I don't have an atomic clone operation - the underlying _kvs // structure is undergoing rapid change. If I just clone the _kvs // field, the CHM in _kvs[0] won't be in sync. // // Wipe out the cloned array (it was shallow anyways). t.clear(); // Now copy sanely for( TypeK K : keySet() ) { final TypeV V = get(K); // Do an official 'get' t.put(K,V); } return t; } catch (CloneNotSupportedException e) { // this shouldn't happen, since we are Cloneable throw new InternalError(); } }
@Override public Enum read( AutoBuffer ab ) { assert _map == null || _map.size()==0; _map = null; if( ab.get1() == 1 ) return this; // Killed? _maxId = ab.get4(); _map = new NonBlockingHashMap<ValueString, Integer>(); int len = 0; while( (len = ab.get2()) != 65535 ) // Read until end-of-map marker _map.put(new ValueString(ab.getA1(len)),ab.get4()); return this; } }
@Override public ddplyPass1 read( AutoBuffer ab ) { super.read(ab); assert _groups == null; _gatherRows = ab.getZ(); _cols = ab.getA4(); _uniq = ab.get(); int len = ab.get4(); if( len == 0 ) return this; _groups = new NonBlockingHashMap<Group,NewChunk>(); for( int i=0; i<len; i++ ) _groups.put(ab.get(Group.class),new NewChunk(null,-99)); return this; } @Override public void copyOver( Freezable dt ) {
@Override public void reduce( ddplyPass1 p1 ) { assert _groups != p1._groups; // Fold 2 hash tables together. // Get the larger hash table in m0, smaller in m1 NonBlockingHashMap<Group,NewChunk> m0 = _groups; NonBlockingHashMap<Group,NewChunk> m1 = p1._groups; if( m0.size() < m1.size() ) { NonBlockingHashMap<Group,NewChunk> tmp=m0; m0=m1; m1=tmp; } // Iterate over smaller table, folding into larger table. for( Group g : m1.keySet() ) { NewChunk nc0 = m0.get(g); NewChunk nc1 = m1.get(g); if( nc0 == null || nc0._len == 0) m0.put(g,nc1); // unimplemented: expected to blow out on large row counts, where we // actually need a collection of chunks, not 1 uber-chunk else if( _gatherRows ) { // All longs are monotonically in-order. Not sure if this is needed // but it's an easy invariant to keep and it makes reading row#s easier. if( nc0._len > 0 && nc1._len > 0 && // len==0 for reduces from remotes (since no rows sent) nc0.at8_impl(nc0._len-1) >= nc1.at8_impl(0) ) nc0.addr(nc1); else if (nc1._len != 0) nc0.add (nc1); } } _groups = m0; p1._groups = null; } @Override public String toString() { return _groups==null ? null : _groups.toString(); }
private int nextInstanceCounter(String algoName, NonBlockingHashMap<String, Integer> instanceCounters) { synchronized (instanceCounters) { int instanceNum = 1; if (instanceCounters.containsKey(algoName)) instanceNum = instanceCounters.get(algoName) + 1; instanceCounters.put(algoName, instanceNum); return instanceNum; } }