/** * Given an id returns the associated grammar node * * @param id the id of interest * @return the grammar node or null if none could be found with the proper id */ private GrammarNode Get(int id) { String name = "G" + id; GrammarNode grammarNode = _nodes.Get(name); if (grammarNode == null) { grammarNode = CreateGrammarNode(id, false); _nodes.Put(name, grammarNode); } return(grammarNode); }
/// <summary> /// Collects adds alternate predecessors for a token that would have lost because of viterbi. /// </summary> /// <param name="token">A token that has an alternate lower scoring predecessor that still might be of interest.</param> /// <param name="predecessor">A predecessor that scores lower than token.getPredecessor()..</param> public void AddAlternatePredecessor(Token token, Token predecessor) { Debug.Assert(predecessor != token.Predecessor); List <Token> list = _viterbiLoserMap.Get(token); if (list == null) { list = new List <Token>(); _viterbiLoserMap.Add(token, list); } list.Add(predecessor); }
public void Test_That_Get_Returns_Correct_Stored_Value() { HashMap testMap = new HashMap(50); string testKey = "key"; string testVal = "val"; testMap.Add(testKey, testVal); testMap.Get(testKey); Assert.Equal(testMap.Get(testKey), testVal); }
public void test_PropertyChange_ParentChild_ToOne() { MaterialType obj2 = EntityFactory.CreateEntity <MaterialType>(); Material mat = EntityFactory.CreateEntity <Material>(); CacheModification.Active = true; try { obj2.Id = 2; obj2.Name = "name2"; obj2.Version = 1; mat.Id = 1; mat.Name = "name1"; mat.Version = 1; mat.ChildMatType = obj2; } finally { CacheModification.Active = false; } HashMap <String, int> matCounter = new HashMap <String, int>(); PropertyChangedEventHandler matHandler = GetPropertyChangeHandler(matCounter); HashMap <String, int> matTypeCounter = new HashMap <String, int>(); PropertyChangedEventHandler matTypeHandler = GetPropertyChangeHandler(matTypeCounter); ((INotifyPropertyChanged)mat).PropertyChanged += matHandler; ((INotifyPropertyChanged)mat.ChildMatType).PropertyChanged += matTypeHandler; mat.ChildMatType.Name += "_change"; WaitForUI(); Assert.AssertEquals(2, matCounter.Count); Assert.AssertTrue(matCounter.ContainsKey("ToBeUpdated")); Assert.AssertTrue(matCounter.ContainsKey("HasPendingChanges")); Assert.AssertEquals(5, matCounter.Get("ToBeUpdated")); Assert.AssertEquals(5, matCounter.Get("HasPendingChanges")); Assert.AssertEquals(5, matTypeCounter.Count); Assert.AssertTrue(matTypeCounter.ContainsKey("Name")); Assert.AssertTrue(matTypeCounter.ContainsKey("Temp1")); Assert.AssertTrue(matTypeCounter.ContainsKey("Temp2")); Assert.AssertTrue(matTypeCounter.ContainsKey("ToBeUpdated")); Assert.AssertTrue(matTypeCounter.ContainsKey("HasPendingChanges")); Assert.AssertEquals(1, matTypeCounter.Get("Name")); Assert.AssertEquals(1, matTypeCounter.Get("Temp1")); Assert.AssertEquals(1, matTypeCounter.Get("Temp2")); Assert.AssertEquals(1, matTypeCounter.Get("ToBeUpdated")); Assert.AssertEquals(1, matTypeCounter.Get("HasPendingChanges")); }
internal Enum GetValue(int value) { lock (dataLock) { var result = customValues.Get(value); if (ReferenceEquals(result, null)) { result = Create(value); customValues.Put(value, result); } return(result); } }
public IPrefetchConfig Add(Type entityType, String propertyPath) { entityType = EntityMetaDataProvider.GetMetaData(entityType).EntityType; List <String> membersToInitialize = entityTypeToPrefetchPaths.Get(entityType); if (membersToInitialize == null) { membersToInitialize = new List <String>(); entityTypeToPrefetchPaths.Put(entityType, membersToInitialize); } membersToInitialize.Add(propertyPath); return(this); }
public void testHashMap() { var hm = new HashMap <int, int>(10); hm.add(10, 10); var num = hm.Get(10); hm.Remove(10); var nill = hm.Get(10); Assert.AreEqual(10, num.value); Assert.AreEqual(nill, null); }
public override void Run(string[] args) { HashMap map = new HashMap(5); map.Insert("zuno", 100); map.Insert("sino", 200); map.Insert("vino", 300); map.Insert("tuno", 400); map.Insert("canu", 500); Debug.Assert(() => map.Get("tuno"), 400); Debug.Assert(() => map.Get("zuno"), 100); }
public static void Main() { HashMap <int, int> map = new HashMap <int, int>(); map.Add(1, 1); map.Add(2, 2); map.Add(3, 3); Console.WriteLine(map.Get(1)); Console.WriteLine(map.Get(2)); Console.WriteLine(map.Get(3)); Console.WriteLine(map.IsEmpty()); Console.WriteLine(map.Size()); Console.WriteLine("Hello World"); }
public object Call(Interpreter interpreter, IList <object> arguments) { LoxInstance instance = new LoxInstance(this); // Constructor LoxFunction initializer = _methods.Get("init"); if (initializer != null) { initializer.Bind(instance).Call(interpreter, arguments); } return(instance); }
public void test_PropertyChange_ToBeUpdated() { HashMap <String, int> pceCounter = new HashMap <String, int>(); PropertyChangedEventHandler handler = GetPropertyChangeHandler(pceCounter); Material obj = EntityFactory.CreateEntity <Material>(); ((INotifyPropertyChanged)obj).PropertyChanged += handler; obj.Id = 1; WaitForUI(); Assert.AssertEquals(1, pceCounter.Get("Id")); Assert.AssertEquals(1, pceCounter.Get("ToBeCreated")); Assert.AssertEquals(1, pceCounter.Get("ToBeUpdated")); Assert.AssertEquals(2, pceCounter.Get("HasPendingChanges")); Assert.AssertEquals(4, pceCounter.Count); pceCounter.Clear(); obj.Id = null; WaitForUI(); Assert.AssertEquals(1, pceCounter.Get("Id")); Assert.AssertEquals(1, pceCounter.Get("ToBeCreated")); Assert.AssertEquals(1, pceCounter.Get("ToBeUpdated")); Assert.AssertEquals(2, pceCounter.Get("HasPendingChanges")); Assert.AssertEquals(4, pceCounter.Count); }
public void testHashMapReHash() { var hm = new HashMap <int, int>(2); hm.add(10, 10); hm.add(11, 11); hm.add(12, 12); Assert.AreEqual(hm.Exist(10), true); Assert.AreEqual(hm.Exist(11), true); Assert.AreEqual(hm.Exist(12), true); Assert.AreEqual(hm.Get(10).value, 10); Assert.AreEqual(hm.Get(11).value, 11); Assert.AreEqual(hm.Get(12).value, 12); }
public void Successfully_Remove_A_Key_And_Value_From_A_HashMap() { HashMap <string> testMap = PopulatedHashMap(); testMap.Remove("Spaceghost"); Assert.Null(testMap.Get("Spaceghost")); }
public override void Unregister(V extension, ConversionKey key) { ParamChecker.AssertParamNotNull(extension, "extension"); ParamChecker.AssertParamNotNull(key, "key"); Object writeLock = GetWriteLock(); lock (writeLock) { base.Unregister(extension, key); ClassTupleEntry <V> classEntry = CopyStructure(); HashMap <Strong2Key <V>, List <Def2Entry <V> > > definitionReverseMap = classEntry.definitionReverseMap; List <Def2Entry <V> > weakEntriesOfStrongType = definitionReverseMap.Remove(new Strong2Key <V>(extension, key)); if (weakEntriesOfStrongType == null) { return; } HashMap <ConversionKey, Object> typeToDefEntryMap = classEntry.typeToDefEntryMap; for (int a = weakEntriesOfStrongType.Count; a-- > 0;) { Def2Entry <V> defEntry = weakEntriesOfStrongType[a]; ConversionKey registeredKey = new ConversionKey(defEntry.sourceType, defEntry.targetType); Object value = typeToDefEntryMap.Get(registeredKey); InterfaceFastList <Def2Entry <V> > list = (InterfaceFastList <Def2Entry <V> >)value; list.Remove(defEntry); if (list.Count == 0) { typeToDefEntryMap.Remove(registeredKey); } TypeToDefEntryMapChanged(classEntry, registeredKey); } this.classEntry = classEntry; } }
public static List <ReturnObject> Traverse(HashMap <string> hash1, HashMap <string> hash2) { List <ReturnObject> list = new List <ReturnObject>(); for (int i = 0; i < hash1.Map.Length; i++) { if (hash1.Map != null) { Node <KeyValuePair <string, string> > current = hash1.Map[i].Head; while (current != null) { if (hash2.Contains(current.Value.Key)) { var rightValue = hash2.Get(current.Value.Key); string value = rightValue.ToString(); ReturnObject holder = new ReturnObject( current.Value.Key, current.Value.Value, value); list.Add(holder); } else { ReturnObject holder = new ReturnObject( current.Value.Key, current.Value.Value, null); list.Add(holder); } current = current.Next; } return(list); } } return(list); }
protected HashMap <Type, IList <XElement> > ReadConfig(XDocument[] docs) { HashMap <Type, IList <XElement> > entities = new HashMap <Type, IList <XElement> >(); foreach (XDocument doc in docs) { IList <XElement> docEntities = new List <XElement>(doc.Descendants(XmlConstants.ENTITY)); for (int a = docEntities.Count; a-- > 0;) { XElement docEntity = docEntities[a]; Type entityType = ResolveEntityType(docEntity); if (entityType == null) { // ignore all entries without a valid entity type mapping continue; } IList <XElement> list = entities.Get(entityType); if (list == null) { list = new List <XElement>(); entities.Put(entityType, list); } list.Add(docEntity); } } return(entities); }
/// <summary> /// Adds a child node holding a pronunciation to the successor. If a node similar to the child has already been /// added, we use the previously added node, otherwise we add this. Also, we record the base unit of the child in the /// set of right context /// </summary> /// <param name="pronunciation">the pronunciation to add</param> /// <param name="probability"></param> /// <returns>the node that holds the pronunciation (new or old)</returns> public WordNode AddSuccessor(Pronunciation pronunciation, float probability, HashMap <Pronunciation, WordNode> wordNodeMap) { WordNode child = null; WordNode matchingChild = (WordNode)GetSuccessor(pronunciation); if (matchingChild == null) { child = wordNodeMap.Get(pronunciation); if (child == null) { child = new WordNode(pronunciation, probability); wordNodeMap.Put(pronunciation, child); } PutSuccessor(pronunciation, child); } else { if (matchingChild.UnigramProbability < probability) { matchingChild.UnigramProbability = probability; } child = matchingChild; } return(child); }
/// <summary> /// Gets a custom attribute from cache or build it. /// </summary> private static Attribute GetAttribute(IAttribute attr) { Attribute result; lock (dataLock) { result = loadedAttributes.Get(attr); if (result != null) { return(result); } } // Not found, build it var builder = attr.AttributeBuilder(); result = (Attribute)builder.Invoke(null, new[] { attr.Annotation() }); // Store in loaded map lock (dataLock) { loadedAttributes.Put(attr, result); } return(result); }
protected void ReallocateObjRefsAndCacheValues(CacheWalkerResult entry, IObjRef[] objRefs, HashMap <IObjRef, int?> allObjRefs) { IObjRef[] oldObjRefs = entry.objRefs; Object[] oldCacheValues = entry.cacheValues; Object[] newCacheValues = new Object[objRefs.Length]; for (int oldIndex = oldObjRefs.Length; oldIndex-- > 0;) { IObjRef oldObjRef = oldObjRefs[oldIndex]; int? newIndex = allObjRefs.Get(oldObjRef); newCacheValues[newIndex.Value] = oldCacheValues[oldIndex]; } entry.cacheValues = newCacheValues; entry.objRefs = objRefs; entry.UpdatePendingChanges(); Object childEntries = entry.childEntries; if (childEntries == null) { return; } if (childEntries.GetType().IsArray) { foreach (CacheWalkerResult childEntry in (CacheWalkerResult[])childEntries) { ReallocateObjRefsAndCacheValues(childEntry, objRefs, allObjRefs); } } else { ReallocateObjRefsAndCacheValues((CacheWalkerResult)childEntries, objRefs, allObjRefs); } }
private void AddToFullRights(HashMap <QNameManager.QName, Right> map) { Iterator <QNameManager.QName> iterator = map.GetKeySet().GetIterator(); while (iterator.HasNext()) { QNameManager.QName key = iterator.Next(); Right right = map.Get(key); Right right2 = this._fullRightsMap.Get(key); if (right2 == null) { right2 = right.Duplicate(); this._fullRightsMap.Put(key, right2); } else { right2.Add(right); } if (right.GrantableRights != null) { if (right2.GrantableRights == null) { right2.GrantableRights = right.GrantableRights.Duplicate(); } else { right2.GrantableRights.Add(right.GrantableRights); } } } }
public static void Values_returns_list_of_Values_Test() { HashMap <StringKey, Item> hashMap = new HashMap <StringKey, Item>(); for (int i = 0; i < 15; i++) { hashMap.Put(new StringKey("item" + i), new Item("item" + i, i, 0.0 + i)); } Entry <StringKey, Item>[] table = hashMap.Table; // get the keys for the map IEnumerator values = hashMap.Values(); int count = 0; // loop through the values of the hashmap values while (values.MoveNext()) { Item currValue = (Item)values.Current; StringKey currKey = new StringKey(currValue.Name); Item matchValue = hashMap.Get(currKey); // The returned value should be the value we looked up with get, based on the same key name Assert.AreEqual(matchValue, currValue); count++; } // The count of the values should be the same as the puts into the table earlier in the test. Assert.AreEqual(hashMap.Size(), count); }
/** * Returns a Word object based on the spelling and its classification. The * behavior of this method is also affected by the properties * wordReplacement and g2pModel * * @param text * the spelling of the word of interest. * @return a Word object * @see edu.cmu.sphinx.linguist.dictionary.Word */ public override Word GetWord(String text) { Word wordObject = wordDictionary.Get(text); if (wordObject != null) { return(wordObject); } String word = dictionary.Get(text); if (word == null) // deal with 'not found' case { this.LogInfo("The dictionary is missing a phonetic transcription for the word '" + text + "'"); if (wordReplacement != null) { wordObject = GetWord(wordReplacement); } else if (g2pModelFile != null && !g2pModelFile.Path.Equals("")) { this.LogInfo("Generating phonetic transcription(s) for the word '" + text + "' using g2p model"); wordObject = ExtractPronunciation(text); wordDictionary.Put(text, wordObject); } } else // first lookup for this string { wordObject = ProcessEntry(text); } return(wordObject); }
public static Assembly GetAssemblyFromType(Type type) { if (TypesPerAssembly == null) return DefaultAssembly; return TypesPerAssembly.Get(type.JavaGetName()) ?? DefaultAssembly; }
public IList <ILoadContainer> GetEntities(IList <IObjRef> orisToLoad) { if (!initialized) { Initialize(); initialized = true; } List <ILoadContainer> result = new List <ILoadContainer>(orisToLoad.Count); lock (databaseMap) { foreach (IObjRef oriToLoad in orisToLoad) { ILoadContainer lc = databaseMap.Get(oriToLoad); if (lc == null) { continue; } result.Add(lc); } result = ObjectCopier.Clone(result); } return(result); }
protected void Initialize() { HashMap <Type, IISet <Type> > typeRelatedByTypes = new HashMap <Type, IISet <Type> >(); IdentityHashSet <IEntityMetaData> extensions = new IdentityHashSet <IEntityMetaData>(GetExtensions().Values()); foreach (IEntityMetaData metaData in extensions) { if (Object.ReferenceEquals(metaData, alreadyHandled)) { continue; } foreach (RelationMember relationMember in metaData.RelationMembers) { AddTypeRelatedByTypes(typeRelatedByTypes, metaData.EntityType, relationMember.ElementType); } } foreach (IEntityMetaData metaData in extensions) { if (Object.ReferenceEquals(metaData, alreadyHandled)) { continue; } Type entityType = metaData.EntityType; IISet <Type> relatedByTypes = typeRelatedByTypes.Get(entityType); if (relatedByTypes == null) { relatedByTypes = new CHashSet <Type>(); } ((EntityMetaData)metaData).TypesRelatingToThis = relatedByTypes.ToArray(); RefreshMembers(metaData); } }
public PropertyInstance GetProperty(String propertyName, NewType propertyType) { PropertyInstance pi = implementedProperties.Get(new PropertyKey(propertyName, propertyType)); if (pi != null) { return(pi); } BindingFlags flags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; PropertyInfo propertyInfo = propertyType != null?CurrentType.GetProperty(propertyName, flags, null, propertyType.Type, Type.EmptyTypes, new ParameterModifier[0]) : CurrentType.GetProperty(propertyName, flags); if (propertyInfo != null) { pi = new PropertyInstance(propertyInfo); } if (pi == null) { MethodInfo m_get = CurrentType.GetMethod("Get" + propertyName, flags); if (m_get == null) { m_get = CurrentType.GetMethod("get" + propertyName, flags); } MethodInfo m_set = CurrentType.GetMethod("Set" + propertyName, flags); if (m_set == null) { m_set = CurrentType.GetMethod("set" + propertyName, flags); } if (m_get != null || m_set != null) { pi = new PropertyInstance(propertyName, m_get != null ? new MethodInstance(m_get) : null, m_set != null ? new MethodInstance(m_set) : null); } } return(pi); }
/// <summary> /// Gets the listener recorded for the given owner with the given (unique) resource id. /// A listener is created if not found and create it set to true. /// </summary> /// <remarks>This method is not thread safe.</remarks> internal static T GetOrCreate <T>(object owner, int resourceId, bool create, Action <T> initialize) where T : class, new() { var weakMap = listeners.Get(resourceId); if (weakMap == null) { if (!create) { return(default(T)); } weakMap = new WeakHashMap <object, object>(); listeners.Put(resourceId, weakMap); } var listener = (T)weakMap.Get(owner); if (listener == null) { if (!create) { return(null); } listener = new T(); weakMap.Put(owner, listener); if (initialize != null) { initialize(listener); } } return(listener); }
/// <summary> /// 获取缓存内容 /// </summary> /// <param name="serviceName"></param> /// <param name="methodName"></param> /// <returns></returns> public static ServiceInfo Get(string serviceName, string methodName) { lock (_locker) { return(_serviceMap.Get(serviceName, methodName)); } }
/** * /// Gets the set of hmm nodes associated with the given end node * * /// @param endNode the end node * /// @return an array of associated hmm nodes */ public HMMNode[] GetHMMNodes(EndNode endNode) { HMMNode[] results = _endNodeMap.Get(endNode.Key); if (results == null) { // System.out.println("Filling cache for " + endNode.getKey() // + " size " + endNodeMap.size()); HashMap <IHMM, HMMNode> resultMap = new HashMap <IHMM, HMMNode>(); Unit baseUnit = endNode.BaseUnit; Unit lc = endNode.LeftContext; foreach (Unit rc in EntryPoints) { IHMM hmm = HMMPool.GetHMM(baseUnit, lc, rc, HMMPosition.End); HMMNode hmmNode = resultMap.Get(hmm); if (hmmNode == null) { hmmNode = new HMMNode(hmm, LogMath.LogOne); resultMap.Add(hmm, hmmNode); } hmmNode.AddRC(rc); foreach (Node node in endNode.GetSuccessors()) { WordNode wordNode = (WordNode)node; hmmNode.AddSuccessor(wordNode); } } // cache it results = resultMap.Values.ToArray(); _endNodeMap.Add(endNode.Key, results); } // System.out.println("GHN: " + endNode + " " + results.length); return(results); }
public void Get() { HashMap <string, int> test = new HashMap <string, int>(); test.Add("One", 1); test.Add("Two", 2); test.Add("Three", 3); test.Add("Four", 4); test.Add("Five", 5); Assert.AreEqual(test.Get("One"), 1); Assert.AreEqual(test.Get("Two"), 2); Assert.AreEqual(test.Get("Three"), 3); Assert.AreEqual(test.Get("Four"), 4); Assert.AreEqual(test.Get("Five"), 5); }
public void TestCache() { Cache<String, String> cache = new HashCache<String, String>(); Map<String, String> map = new HashMap<String, String>(); for(int i = 0; i < LOAD_COUNT; i++) { String key = i.ToString(); cache.Insert(key, key); map.Put(key, key); } for(int i = 0; i < LOAD_COUNT; i++) { String key = i.ToString(); AssertEquals(cache.Fetch(key), key); AssertEquals(map.Get(key), cache.Fetch(key)); } }
private QueryPhraseMap GetOrNewMap(HashMap<String, QueryPhraseMap> subMap, String term) { QueryPhraseMap map = subMap.Get(term); if (map == null) { map = new QueryPhraseMap(fieldQuery); subMap.Put(term, map); } return map; }