好的算法来管理使用通配符配置树? [英] Good algorithm for managing configuration trees with wildcards?

查看:147
本文介绍了好的算法来管理使用通配符配置树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个好的算法在树通配符的形式管理配置变量(XYZ,X .Z,X。的。*等)。

I am searching for a good algorithm for managing configuration variables in form of tree with wildcards (x.y.z, x..z, x..* etc.).

有一些与搜索时间为O(N)的更好吗? (插入/删除时间不那么重要)。

Is there something with search time better than O(N)? (insert / delete time are not so important).

目前我有一个平坦的列表(对的key =>值),我搜索所有的匹配值,然后对它们进行排序按重要性(基本上,更多的通配符=>不那么重要),并选择一种最佳成绩。

Currently I have a flat list (pairs key=>value), and I search all matching values, then sort them by importance (basically, more wildcards => less important) and choose one with best score.

推荐答案

由于墓志铭指出,一个线索或基数树会做的伎俩。基数树一般会更多的空间efficent。

As epitaph points out, a trie or radix-tree will do the trick. A radix-tree will generally be more space efficent.

我想有几十个实现在那里。看看我的实现这里

I guess there are a dozens of implementations out there. Take a look at my implementation here.

查找()的将允许你搜索一个给定的关键。

lookup() will allow you to search for a given key.

startwith()的将返回所有这些键和开始与传递的字符串及其对应的值。它实际上是一个通配符搜索。

startwith() will return all those keys and their corresponding values that start with the passed string. It is effectively a wild-card search.

这篇关于好的算法来管理使用通配符配置树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆