Ejemplo n.º 1
0
 public static void demoFailureCase()
 {
     Console.WriteLine("Demo-ing failure case: false positive for non-inserted key:");
     PCADLO.PCADLODictionary<string, string> map = new PCADLO.PCADLODictionary<string, string>();
     map.Add("y5ymMhdR", "y5ymMhdR");    //note, key "KRHliuFh" is NOT inserted
     string val = null;
     string nonInsertedKey = "KRHliuFh";
     map.TryGetValue(nonInsertedKey, out val);
     Console.WriteLine("getting non-inserted key \""+nonInsertedKey+"\" from map "+ map.ToString()+"\nreturns value: "+val);
     //DictionaryExtensions.PrettyPrint<string, string>(map)
 }
Ejemplo n.º 2
0
    public static void demoFailureCase()
    {
        Console.WriteLine("Demo-ing failure case: false positive for non-inserted key:");
        PCADLO.PCADLODictionary <string, string> map = new PCADLO.PCADLODictionary <string, string>();
        map.Add("y5ymMhdR", "y5ymMhdR");    //note, key "KRHliuFh" is NOT inserted
        string val            = null;
        string nonInsertedKey = "KRHliuFh";

        map.TryGetValue(nonInsertedKey, out val);
        Console.WriteLine("getting non-inserted key \"" + nonInsertedKey + "\" from map " + map.ToString() + "\nreturns value: " + val);
        //DictionaryExtensions.PrettyPrint<string, string>(map)
    }
Ejemplo n.º 3
0
    void validateMaps(List <string> keyList, Dictionary <string, string> map1, PCADLO.PCADLODictionary <string, string> map2, string validateMethod)
    {
        int nSearchSpace = keyList.Count;

        if (nInserts < nSearchSpace)
        {
            nInserts = nSearchSpace;
        }
        //reset seed for repeatibility between iterations
        random = new Random(seed);
        Console.WriteLine("Starting...");
        //long t1 = System.Environment.TickCount;
        bool validated = true;

        bool expKeys = validateMethod.Equals("valid8-expkeys");

        if (expKeys)
        {
            //map2.setExpectedKeys(keyList);
        }

        //else insert randomly (overwriting inserts ok)
        for (int i = 0; i < nInserts; i++)
        {
            string key = null;
            if (i < nKeys)
            {
                //if more keys than nInserts, insert them all
                key = keyList[i];
            }
            else
            {
                //else re-insert previously inserted one (test for collisions while overwriting)
                key = keyList[random.Next(nKeys)];
            }
            string k = string.Copy(key);
            map1.Add(k, key);
            map2.Add(k, key);
            if (!expKeys && (map1.Count != map2.Count))
            {
                Console.WriteLine("Inconsistency at put(" + k + "): " + map1.Count + " != " + map2.Count);
                validated = false;
                //System.exit(1);
            }
        }

        for (int i = 0; i < nLookups; i++)
        {
            string key  = keyList[random.Next(nSearchSpace)];
            string val1 = null;
            string val2 = null;
            map1.TryGetValue(key, out val1);
            map2.TryGetValue(key, out val2);
            if (val1 != val2)
            {
                Console.WriteLine("Inconsistency at get(" + key + "[hash:" + EqualityComparer <string> .Default.GetHashCode(key) + "]): " + val1 + "[hash:" + EqualityComparer <string> .Default.GetHashCode(val1) + "] != " + val2 + "[hash:" + EqualityComparer <string> .Default.GetHashCode(val2) + "]");
                //Console.WriteLine("hash["+key+"]="+key.hashCode()+" hash["+val1+"]="+(val1 != null ? val1.hashCode() : null)+" hash["+val2+"]="+(val2 != null ? val2.hashCode() : null));
                validated = false;
                //System.exit(1);
            }
        }
        if (nRemoves >= nSearchSpace)
        {
            nRemoves = nSearchSpace;
        }
        for (int i = 0; i < nRemoves; i++)
        {
            string key  = keyList[i];
            bool   val1 = map1.Remove(key);
            bool   val2 = map2.Remove(key);
            if (val1 != val2)
            {
                Console.WriteLine("Inconsistency at remove(" + key + "): " + val1 + " != " + val2);
                validated = false;
                //System.exit(1);
            }
        }
        if (validated)
        {
            Console.WriteLine("Map operation validated");
        }
        else
        {
            Console.WriteLine("Map operation not validated");
        }
        Environment.Exit(0);
    }