コード例 #1
0
 /// <summary>
 /// Combine another order list into this.
 /// </summary>
 /// <param name="list">The list to incoroporate.</param>
 public void Include(KeyScoreOrderedList list)
 {
     foreach (var pair in list.scoredKeys)
     {
         Include(pair.key, pair.score);
     }
 }
コード例 #2
0
        internal static KeyScoreOrderedList Read(BinaryReader reader)
        {
            var list = new KeyScoreOrderedList();

            var scoredKeysCount = reader.ReadInt32();

            for (var index = 0; index < scoredKeysCount; index++)
            {
                var key   = reader.ReadInt32();
                var score = reader.ReadDouble();

                list.Include(key, score);
            }

            return(list);
        }
コード例 #3
0
        void DumpPrefixes(int lowerPosition, int upperPosition)
        {
            if (lowerPosition < upperPosition)
            {
                if (lowerPosition + 1 == upperPosition)
                {
                    var key = _dictionaryList[lowerPosition].key;

                    Debug.Write("  :");
                    foreach (var word in key)
                    {
                        Debug.Write(" " + word);
                    }
                    Debug.Write(" =>");

                    foreach (var pair in _dictionaryList[lowerPosition].predictions.KeyScorePairs)
                    {
                        Debug.Write(" " + pair.key);
                    }

                    Debug.WriteLine("");
                }
                else
                {
                    var combined = new KeyScoreOrderedList();

                    for (var position = lowerPosition; position < upperPosition; position++)
                    {
                        foreach (var pair in _dictionaryList[position].predictions.KeyScorePairs)
                        {
                            combined.Include(pair.key, pair.score);
                        }
                    }

                    Debug.Write(" : * =>");

                    foreach (var pair in combined.KeyScorePairs)
                    {
                        Debug.Write(" " + pair.key);
                    }

                    Debug.WriteLine("");
                }
            }
        }
コード例 #4
0
        internal static DictionaryEntry Read(BinaryReader reader)
        {
            var predictions = KeyScoreOrderedList.Read(reader);

            var keyLength = reader.ReadInt32();
            var key       = new int[keyLength];

            for (var keyIndex = 0; keyIndex < keyLength; keyIndex++)
            {
                key[keyIndex] = reader.ReadInt32();
            }

            var entry = new DictionaryEntry {
                predictions = predictions, key = key
            };

            return(entry);
        }
コード例 #5
0
        KeyScoreOrderedList GetCombinedSliceSuggestions(int startLhs, int limitLhs, int startRhs, int limitRhs)
        {
            Debug.Assert(startLhs < limitLhs);
            Debug.Assert(limitLhs <= startRhs);
            Debug.Assert(startRhs <= limitRhs);

            var key = new[] { startLhs, limitLhs, startRhs, limitRhs };

            WeakReference <KeyScoreOrderedList> reference;

            _cache.TryGetValue(key, out reference);

            KeyScoreOrderedList list;

            if (reference == null || !reference.TryGetTarget(out list))
            {
                if (reference != null)
                {
                    Debug.WriteLine("Cache item garbage collected");
                }

                list = new KeyScoreOrderedList();

                for (var indexLhs = startLhs; indexLhs < limitLhs; indexLhs++)
                {
                    list.Include(_dictionaryList[indexLhs].predictions);
                }

                for (var indexRhs = startRhs; indexRhs < limitRhs; indexRhs++)
                {
                    list.Include(_dictionaryList[indexRhs].predictions);
                }

                _cache[key] = new WeakReference <KeyScoreOrderedList>(list);
            }
            else
            {
                Debug.WriteLine($"Cache hit! [{startLhs}..{limitLhs})={limitLhs - startLhs} & [{startRhs}..{limitRhs})={limitRhs - startRhs} :=> {limitLhs - startLhs + limitRhs - startRhs}");
            }

            return(list);
        }