有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何访问ApachePatriciaTrieEntry密钥?

在我的应用程序中,我有大约50Mb的字符串,其中有很多公共部分。 我想通过使用基数Trie(Patricia Tree)来减少内存消耗,例如apachecollections impl

目标是保留对条目的引用,并在需要时获取完整字符串:

val trie = PatriciaTrie()
val node1 = trie.put("Long string #1", null) // what's the method to add and return TrieEntry?
someObject1.setNode(node1)
val node2 = trie.put("Long string #2", null)
someObject2.setNode(node2)
val node3 = trie.put("Long string #3", null)
someObject3.setNode(node3)

因此,我希望它存储在内存中,如下所示:

 root
  \
   "Long string #"
                 \"1"
                 \"2"
                 \"3"

需要时,我应该能够获取完整字符串(在someObjectN中):

 val fullString = node.getKey(); // How can i do it?

有两个问题:

  1. 如何将字符串放入trie并获取TrieEntry实例?由于它实现了java.util.mapputmethod返回值:

    public V put(final K key, final V value)

  2. 如何从TrieEntry实例获取完整字符串

值(节点负载)在我的用例中是无用的,因为主要目标只是节省内存(没有任何负载)

Apache's PatriciaTrie是否适合该用例? 有什么想法吗


共 (0) 个答案