Example #1
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);
        }
Example #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);
        }
Example #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("");
                }
            }
        }