private Set<Map.Entry<Object, ClassicCounter<K>>> lowestLevelCounterEntrySet(Set<Map.Entry<Object, ClassicCounter<K>>> s, Object[] key, boolean useLists) {
    Set<K> keys = map.keySet();
    if (depth == 2) {
      // add these counters to set
      for (K finalKey: keys) {
        K[] newKey = ErasureUtils.<K>mkTArray(Object.class,key.length + 1);
        if (key.length > 0) {
          System.arraycopy(key, 0, newKey, 0, key.length);
        }
        newKey[key.length] = finalKey;
        ClassicCounter<K> c = conditionalizeHelper(finalKey).oneDimensionalCounterView();
        if (useLists) {
          s.add(new Entry<Object,ClassicCounter<K>>(Arrays.asList(newKey), c));
        } else {
          s.add(new Entry<Object,ClassicCounter<K>>(newKey[0], c));
        }
      }
    } else {
      //System.out.println("key length " + key.length);
      //System.out.println("keyset level " + depth + " " + keys);
      for (K o: keys) {
        Object[] newKey = new Object[key.length + 1];
        if (key.length > 0) {
          System.arraycopy(key, 0, newKey, 0, key.length);
        }
        newKey[key.length] = o;
        //System.out.println("level " + key.length + " current key " + Arrays.asList(newKey));
        conditionalizeHelper(o).lowestLevelCounterEntrySet(s, newKey, true);
      }
    }
    //System.out.println("leaving key length " + key.length);
    return s;
  }
private Set < Map . Entry < Object , ClassicCounter < K > > > lowestLevelCounterEntrySet ( Set < Map . Entry < Object , ClassicCounter < K > > > s , Object [ ] key , boolean useLists ) { Set < K > keys = map . keySet ( ) ; if ( depth == 2 ) { for ( K finalKey : keys ) { K [ ] newKey = ErasureUtils . < K > mkTArray ( Object . class , key . length + 1 ) ; if ( key . length > 0 ) { System . arraycopy ( key , 0 , newKey , 0 , key . length ) ; } newKey [ key . length ] = finalKey ; ClassicCounter < K > c = conditionalizeHelper ( finalKey ) . oneDimensionalCounterView ( ) ; if ( useLists ) { s . add ( new Entry < Object , ClassicCounter < K > > ( Arrays . asList ( newKey ) , c ) ) ; } else { s . add ( new Entry < Object , ClassicCounter < K > > ( newKey [ 0 ] , c ) ) ; } } } else { for ( K o : keys ) { Object [ ] newKey = new Object [ key . length + 1 ] ; if ( key . length > 0 ) { System . arraycopy ( key , 0 , newKey , 0 , key . length ) ; } newKey [ key . length ] = o ; conditionalizeHelper ( o ) . lowestLevelCounterEntrySet ( s , newKey , true ) ; } } return s ; }
/* this is (non-tail) recursive right now, haven't figured out a way
to speed it up