2009-07-02 12 views
6

क्या क्रिट-बिट पेड़ का प्रतिनिधित्व करने के लिए जावा में अंतर्निहित डेटा संरचना है? या कोई पुस्तकालय उपलब्ध है जो इस कार्यक्षमता प्रदान कर सकता है? मैं संक्षिप्त कोड को उत्तर के रूप में भी स्वीकार करता हूं, अगर किसी को सरल संक्षिप्त तरीके से कार्यान्वित किया जा सकता है।जावा क्रिट-बिट पेड़

उत्तर

5

क्या आपने radixtree जावा प्रोजेक्ट का प्रयास किया था?

आप इसे में संरचना आप देख रहे हैं, की तरह मिल सकती है:

  • RadixTree वर्ग

(उद्धरण):

/** 
* This interface represent the operation of a radix tree. A radix tree, 
* Patricia trie/tree, or crit bit tree is a specialized set data structure 
* based on the trie that is used to store a set of strings. In contrast with a 
* regular trie, the edges of a Patricia trie are labelled with sequences of 
* characters rather than with single characters. These can be strings of 
* characters, bit strings such as integers or IP addresses, or generally 
* arbitrary sequences of objects in lexicographical order. Sometimes the names 
* radix tree and crit bit tree are only applied to trees storing integers and 
* Patricia trie is retained for more general inputs, but the structure works 
* the same way in all cases. 
* 
* @author Tahseen Ur Rehman 
* email: tahseen.ur.rehman {at.spam.me.not} gmail.com 
*/ 
public interface RadixTree<T> { 
    /** 
    * Insert a new string key and its value to the tree. 
    * 
    * @param key 
    *   The string key of the object 
    * @param value 
    *   The value that need to be stored corresponding to the given 
    *   key. 
    * @throws DuplicateKeyException 
    */ 
    public void insert(String key, T value) throws DuplicateKeyException; 
  • RadixTreeNode कक्षा

(उद्धरण):

/** 
* Represents a node of a Radix tree {@link RadixTreeImpl} 
* 
* @author Tahseen Ur Rehman 
* @email tahseen.ur.rehman {at.spam.me.not} gmail.com 
* @param <T> 
*/ 
class RadixTreeNode<T> { 
    private String key; 

    private List<RadixTreeNode<T>> childern; 

    private boolean real; 

    private T value; 

    /** 
    * intailize the fields with default values to avoid null reference checks 
    * all over the places 
    */ 
     public RadixTreeNode() { 
     key = ""; 
     childern = new ArrayList<RadixTreeNode<T>>(); 
     real = false; 
    } 
2

एक अन्य विकल्प rkapsi के patricia-trie है, या आप कुछ थोड़ा कम जटिल है कि आप अपने आप पर हैक कर सकते हैं के लिए देख रहे हैं, तो आप अपने simple-patricia-trie कोशिश कर सकते हैं।

मुझे functional-critbit कार्यान्वयन भी उपलब्ध है जो अंतरिक्ष दक्षता पर केंद्रित है (हालांकि इसका प्रदर्शन ठीक है)। यह दोनों परिवर्तनीय और अपरिवर्तनीय स्वादों में आता है।

+0

' टी डाली (वस्तु ओ)' श्री परेशान। संकलक। अगर आप ग्रहण का उपयोग कर निर्माण करते हैं तो उत्सुक? ग्रहण का कंपाइलर आपको इस तरह की चीज़ों से दूर जाने देता है। – alphazero

+0

हाँ, ग्रहण कभी-कभी मुझे उस पर काटता है, लेकिन वर्तमान सिर तक 0.0.4 सीधे जवाक के साथ ठीक संकलित करना चाहिए। इस तरह की एक कास्ट विधि एक जगह पर अनचेक कास्ट चेतावनियों को अलग करने के लिए एक बहुत ही सामान्य क्लज है, और मेरे पास कभी भी मामूली समस्याओं से अधिक कुछ नहीं था [https://github.com/jfager/functional-critbit/ प्रतिबद्ध/6bbc21fee45b0bef9fff1eae1945c4eec35dc517) जब मैं इसका उपयोग करता हूं। यदि आप जो देख रहे हैं उसके बारे में अधिक जानकारी के साथ आप एक जिथब मुद्दा खोल सकते हैं, तो मैं इसकी सराहना करता हूं। – jfager

+0

rkapsi के कार्यान्वयन के लिए https://github.com/jfager/functional-critbit/issues/1 – alphazero

संबंधित मुद्दे