예제 #1
0
        internal int DecrementCount(TokenPredictorInfo child, int increment)
        {
            Debug.Assert(ReferenceEquals(child, _database[child.Token]));
            var value = child.DecrementCount(increment);

            _isSortedDatabaseValid = false;

            return(value);
        }
예제 #2
0
        private int SortedDictionaryComparison(TokenPredictorInfo x,
                                               TokenPredictorInfo y)
        {
            var value = y.Count.CompareTo(x.Count);

            if (value == 0)
            {
                value = y.Token.CompareTo(x.Token);
            }
            return(value);
        }
예제 #3
0
        internal TokenPredictorInfo GetValue(int token)
        {
            if (!_database.TryGetValue(token, out var info))
            {
                info = new TokenPredictorInfo(token);
                _database.Add(token, info);

                if (_sortedDatabase != null)
                {
                    _sortedDatabase.Add(info);

                    _isSortedDatabaseValid = false;
                }
                Debug.Assert(!_isSortedDatabaseValid);
            }

            return(info);
        }
예제 #4
0
        internal bool TryGetValue(int token, out TokenPredictorInfo info)
        {
            var value = _database.TryGetValue(token, out info);

            return(value);
        }
예제 #5
0
 internal void IncrementCount(TokenPredictorInfo child, int increment)
 {
     Debug.Assert(ReferenceEquals(child, _database[child.Token]));
     child.IncrementCount(increment);
     _isSortedDatabaseValid = false;
 }
예제 #6
0
        private static IDictionary <string, object> ToJsonDictionary(StringTokens tokens, TokenPredictorInfo info)
        {
            var saved = new SortedDictionary <string, object>
            {
                { "#", info.Count }
            };

            var children = info.TryGetChildren();

            if (children != null)
            {
                var value = ToJsonDictionary(tokens, children);
                saved.Add("~", value);
            }

            return(saved);
        }