Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #4
0
        internal bool TryGetValue(int token, out TokenPredictorInfo info)
        {
            var value = _database.TryGetValue(token, out info);

            return(value);
        }
Exemple #5
0
 internal void IncrementCount(TokenPredictorInfo child, int increment)
 {
     Debug.Assert(ReferenceEquals(child, _database[child.Token]));
     child.IncrementCount(increment);
     _isSortedDatabaseValid = false;
 }
Exemple #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);
        }