Example #1
0
            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 >();
            }
Example #2
0
 public static IEnumerable <MModelRecord> GetAllModelRecords(this DictionaryNative dict)
 {
     foreach (var p in dict)
     {
         yield return(p.ToModelRecord());
     }
 }
Example #3
0
 public ValueCollection( DictionaryNative dictionary )
 {
     if ( dictionary == null )
     {
         throw (new ArgumentNullException( "dictionary" ));
     }
     this._Dictionary = dictionary;
 }
Example #4
0
 public void Initialize(int capacity)
 {
     if (DictionaryNative == null)
     {
         Capacity         = capacity;
         DictionaryNative = new DictionaryNative(capacity);
         LoadMMFCallback  = new LoadModelFilenameContentCallback(DictionaryNative.AddNewOrToEndOfChain);
     }
 }
Example #5
0
 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 ] );
         }
     }
 }
Example #6
0
        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
        }
Example #7
0
 private void DisposeNativeResources()
 {
     if (_Dictionary != null)
     {
         foreach (var ptr in _Dictionary.Keys)
         {
             Marshal.FreeHGlobal(ptr);
         }
         _Dictionary.Dispose();
         _Dictionary = null;
     }
 }
Example #8
0
 internal Enumerator( DictionaryNative dictionary )
 {
     _Dictionary = dictionary;
     _Index = 0;
     _CurrentValue = default(BucketValue);
 }
Example #9
0
 internal Enumerator( DictionaryNative dictionary )
 {
     _Dictionary = dictionary;
     _Index = 0;
     _CurrentKey = default(IntPtr);
 }