private int _GetEnumeratorRetType; // What should Enumerator.Current return? internal Enumerator( DictionaryNative dictionary, int getEnumeratorRetType ) { _Dictionary = dictionary; _Index = 0; _GetEnumeratorRetType = getEnumeratorRetType; _Current = new KeyValuePair< IntPtr, BucketValue >(); }
public static IEnumerable <MModelRecord> GetAllModelRecords(this DictionaryNative dict) { foreach (var p in dict) { yield return(p.ToModelRecord()); } }
public ValueCollection( DictionaryNative dictionary ) { if ( dictionary == null ) { throw (new ArgumentNullException( "dictionary" )); } this._Dictionary = dictionary; }
public void Initialize(int capacity) { if (DictionaryNative == null) { Capacity = capacity; DictionaryNative = new DictionaryNative(capacity); LoadMMFCallback = new LoadModelFilenameContentCallback(DictionaryNative.AddNewOrToEndOfChain); } }
public void MergeWith( DictionaryNative dict ) { for ( int index = 0, len = dict._Count; index < len; index++ ) { if ( 0 <= dict._Entries[ index ].hashCode ) { AddNewOrMergeWithExists( ref dict._Entries[ index ] ); } } }
private void ParallelLoadMMF(MModelConfig config) { #region [.parallel load by partitions.] var processorCount = Environment.ProcessorCount; var partitions = config.LanguageConfigs.SplitByPartitionCountOrGreater(processorCount); var unitBag = new ConcurrentBag <ParallelLoadUnit>(); Parallel.ForEach(partitions, new ParallelOptions() { MaxDegreeOfParallelism = processorCount }, () => default(ParallelLoadUnit), (partition, loopState, i, unit) => { const int EMPIRICALLY_CHOSEN_FUSKING_NUMBER = 27; var capacity = (int)(partition.TotalModelFilenameLengths / EMPIRICALLY_CHOSEN_FUSKING_NUMBER); unit.Initialize(capacity); foreach (var languageConfig in partition.LanguageConfigs) { LanguageModelFileReaderMMF.Read(languageConfig, unit.LoadMMFCallback); } return(unit); }, (unit) => { if (unit.DictionaryNative != null && unit.DictionaryNative.Count != 0) { unitBag.Add(unit); } } ); #endregion #region [.merge.] var dictionary = new DictionaryNative(config.ModelDictionaryCapacity); foreach (var dict in unitBag.Select(unit => unit.DictionaryNative)) { dictionary.MergeWith(dict); dict.Dispose(); } _Dictionary = dictionary; unitBag = null; #endregion }
private void DisposeNativeResources() { if (_Dictionary != null) { foreach (var ptr in _Dictionary.Keys) { Marshal.FreeHGlobal(ptr); } _Dictionary.Dispose(); _Dictionary = null; } }
internal Enumerator( DictionaryNative dictionary ) { _Dictionary = dictionary; _Index = 0; _CurrentValue = default(BucketValue); }
internal Enumerator( DictionaryNative dictionary ) { _Dictionary = dictionary; _Index = 0; _CurrentKey = default(IntPtr); }