Esempio n. 1
0
        public void TryGetValue_EmptyTree_NotFound(string input)
        {
            // Arrange
            var radixTree = new RadixTree <int>();

            // Act
            var found = radixTree.TryGetValue(input, out int _);

            // Assert
            Assert.False(found, "should not find value");
        }
Esempio n. 2
0
        public void TryGetValue_ExistingKey_ReturnsValue(string input)
        {
            // Arrange
            var rand = new Random();
            var keys = new[] {
                "",
                "foo",
            };
            var dictionary = keys.ToDictionary(x => x, _ => rand.Next());
            var radixTree  = new RadixTree <int>(dictionary);

            // Act
            var found = radixTree.TryGetValue(input, out int value);

            // Assert
            Assert.True(found, "should find value");
            Assert.Equal(dictionary[input], value);
        }
Esempio n. 3
0
        public static (GetRule, PathExpander) Parse(IDictionary <string, RuleDefinition> rules, GetRuleParser parserResolver)
        {
            var tree = new RadixTree <IRule>(rules.ToDictionary(x => x.Key.ToLower(), x => parserResolver(x.Value.Format).Parse(x.Value.Payload)));

            Option <IRule> RulesRepository(ConfigurationPath path) => tree.TryGetValue(path, out var rule) ? Option <IRule> .Some(rule) : Option <IRule> .None;

            IEnumerable <ConfigurationPath> PathExpander(ConfigurationPath path)
            {
                if (!path.IsScan)
                {
                    return new[] { path }
                }
                ;

                var keys = path == ConfigurationPath.FullScan
                    ? tree.Keys
                    : tree.ListPrefix($"{path.Folder}/").Select(c => c.key);

                return(keys.Select(ConfigurationPath.New).Where(x => !x.IsHidden(path.Folder)));
            }

            return(RulesRepository, PathExpander);
        }
    }