Exemplo n.º 1
0
 /* this is (non-tail) recursive right now, haven't figured out a way
  * to speed it up */
 private ICollection <KeyValuePair <object, double> > EntrySet(ICollection <KeyValuePair <object, double> > s, object[] key, bool useLists)
 {
     if (depth == 1)
     {
         //System.out.println("key is long enough to add to set");
         ICollection <K> keys = map.Keys;
         foreach (K finalKey in keys)
         {
             // array doesn't escape
             K[] newKey = ErasureUtils.MkTArray <K>(typeof(object), key.Length + 1);
             if (key.Length > 0)
             {
                 System.Array.Copy(key, 0, newKey, 0, key.Length);
             }
             newKey[key.Length] = finalKey;
             MutableDouble value  = (MutableDouble)map[finalKey];
             double        value1 = value;
             if (useLists)
             {
                 s.Add(new GeneralizedCounter.Entry <object, double>(Arrays.AsList(newKey), value1));
             }
             else
             {
                 s.Add(new GeneralizedCounter.Entry <object, double>(newKey[0], value1));
             }
         }
     }
     else
     {
         ICollection <K> keys = map.Keys;
         //System.out.println("key length " + key.length);
         //System.out.println("keyset level " + depth + " " + keys);
         foreach (K o in keys)
         {
             object[] newKey = new object[key.Length + 1];
             if (key.Length > 0)
             {
                 System.Array.Copy(key, 0, newKey, 0, key.Length);
             }
             newKey[key.Length] = o;
             //System.out.println("level " + key.length + " current key " + Arrays.asList(newKey));
             ConditionalizeHelper(o).EntrySet(s, newKey, true);
         }
     }
     //System.out.println("leaving key length " + key.length);
     return(s);
 }
Exemplo n.º 2
0
        /* this is (non-tail) recursive right now, haven't figured out a way
         * to speed it up */
        private ICollection <KeyValuePair <object, ClassicCounter <K> > > LowestLevelCounterEntrySet(ICollection <KeyValuePair <object, ClassicCounter <K> > > s, object[] key, bool useLists)
        {
            ICollection <K> keys = map.Keys;

            if (depth == 2)
            {
                // add these counters to set
                foreach (K finalKey in keys)
                {
                    K[] newKey = ErasureUtils.MkTArray <K>(typeof(object), key.Length + 1);
                    if (key.Length > 0)
                    {
                        System.Array.Copy(key, 0, newKey, 0, key.Length);
                    }
                    newKey[key.Length] = finalKey;
                    ClassicCounter <K> c = ConditionalizeHelper(finalKey).OneDimensionalCounterView();
                    if (useLists)
                    {
                        s.Add(new GeneralizedCounter.Entry <object, ClassicCounter <K> >(Arrays.AsList(newKey), c));
                    }
                    else
                    {
                        s.Add(new GeneralizedCounter.Entry <object, ClassicCounter <K> >(newKey[0], c));
                    }
                }
            }
            else
            {
                //System.out.println("key length " + key.length);
                //System.out.println("keyset level " + depth + " " + keys);
                foreach (K o in keys)
                {
                    object[] newKey = new object[key.Length + 1];
                    if (key.Length > 0)
                    {
                        System.Array.Copy(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);
        }