Java Doc for TernaryTree.java in  » PDF » pdf-itext » com » lowagie » text » pdf » hyphenation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » PDF » pdf itext » com.lowagie.text.pdf.hyphenation 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.lowagie.text.pdf.hyphenation.TernaryTree

All known Subclasses:   com.lowagie.text.pdf.hyphenation.HyphenationTree,
TernaryTree
public class TernaryTree implements Cloneable,Serializable(Code)

Ternary Search Tree.

A ternary search tree is a hibrid between a binary tree and a digital search tree (trie). Keys are limited to strings. A data value of type char is stored in each leaf node. It can be used as an index (or pointer) to the data. Branches that only contain one key are compressed to one node by storing a pointer to the trailer substring of the key. This class is intended to serve as base class or helper class to implement Dictionary collections or the like. Ternary trees have some nice properties as the following: the tree can be traversed in sorted order, partial matches (wildcard) can be implemented, retrieval of all keys within a given distance from the target, etc. The storage requirements are higher than a binary tree but a lot less than a trie. Performance is comparable with a hash table, sometimes it outperforms a hash function (most of the time can determine a miss faster than a hash).

The main purpose of this java port is to serve as a base for implementing TeX's hyphenation algorithm (see The TeXBook, appendix H). Each language requires from 5000 to 15000 hyphenation patterns which will be keys in this tree. The strings patterns are usually small (from 2 to 5 characters), but each char in the tree is stored in a node. Thus memory usage is the main concern. We will sacrify 'elegance' to keep memory requirenments to the minimum. Using java's char type as pointer (yes, I know pointer it is a forbidden word in java) we can keep the size of the node to be just 8 bytes (3 pointers and the data char). This gives room for about 65000 nodes. In my tests the english patterns took 7694 nodes and the german patterns 10055 nodes, so I think we are safe.

All said, this is a map with strings as keys and char as value. Pretty limited!. It can be extended to a general map by using the string representation of an object and using the char value as an index to an array that contains the object values.


author:
   cav@uniscope.co.jp

Inner Class :public class Iterator implements Enumeration

Field Summary
final protected static  intBLOCK_SIZE
    
protected  char[]eq
     Pointer to equal branch and to data when this node is a string terminator.
protected  charfreenode
    
protected  char[]hi
     Pointer to high branch.
protected  CharVectorkv
     This vector holds the trailing of the keys when the branch is compressed.
protected  intlength
    
protected  char[]lo
    
protected  charroot
    
protected  char[]sc
    

The character stored in this node: splitchar.


Constructor Summary
 TernaryTree()
    

Method Summary
public  voidbalance()
    
public  Objectclone()
    
public  intfind(String key)
    
public  intfind(char[] key, int start)
    
protected  voidinit()
    
public  voidinsert(String key, char val)
     Branches are initially compressed, needing one node per key plus the size of the string key.
public  voidinsert(char[] key, int start, char val)
    
protected  voidinsertBalanced(String[] k, char[] v, int offset, int n)
     Recursively insert the median first and then the median of the lower and upper halves, and so on in order to get a balanced tree.
public  Enumerationkeys()
    
public  booleanknows(String key)
    
public  voidprintStats()
    
public  intsize()
    
public static  intstrcmp(char[] a, int startA, char[] b, int startB)
    
public static  intstrcmp(String str, char[] a, int start)
    
public static  voidstrcpy(char[] dst, int di, char[] src, int si)
    
public static  intstrlen(char[] a, int start)
    
public static  intstrlen(char[] a)
    
public  voidtrimToSize()
     Each node stores a character (splitchar) which is part of some key(s).

Field Detail
BLOCK_SIZE
final protected static int BLOCK_SIZE(Code)



eq
protected char[] eq(Code)
Pointer to equal branch and to data when this node is a string terminator.



freenode
protected char freenode(Code)



hi
protected char[] hi(Code)
Pointer to high branch.



kv
protected CharVector kv(Code)
This vector holds the trailing of the keys when the branch is compressed.



length
protected int length(Code)



lo
protected char[] lo(Code)
Pointer to low branch and to rest of the key when it is stored directly in this node, we don't have unions in java!



root
protected char root(Code)



sc
protected char[] sc(Code)

The character stored in this node: splitchar. Two special values are reserved:

  • 0x0000 as string terminator
  • 0xFFFF to indicate that the branch starting at this node is compressed

This shouldn't be a problem if we give the usual semantics to strings since 0xFFFF is garanteed not to be an Unicode character.





Constructor Detail
TernaryTree
TernaryTree()(Code)




Method Detail
balance
public void balance()(Code)
Balance the tree for best search performance



clone
public Object clone()(Code)



find
public int find(String key)(Code)



find
public int find(char[] key, int start)(Code)



init
protected void init()(Code)



insert
public void insert(String key, char val)(Code)
Branches are initially compressed, needing one node per key plus the size of the string key. They are decompressed as needed when another key with same prefix is inserted. This saves a lot of space, specially for long keys.



insert
public void insert(char[] key, int start, char val)(Code)



insertBalanced
protected void insertBalanced(String[] k, char[] v, int offset, int n)(Code)
Recursively insert the median first and then the median of the lower and upper halves, and so on in order to get a balanced tree. The array of keys is assumed to be sorted in ascending order.



keys
public Enumeration keys()(Code)



knows
public boolean knows(String key)(Code)



printStats
public void printStats()(Code)



size
public int size()(Code)



strcmp
public static int strcmp(char[] a, int startA, char[] b, int startB)(Code)
Compares 2 null terminated char arrays



strcmp
public static int strcmp(String str, char[] a, int start)(Code)
Compares a string with null terminated char array



strcpy
public static void strcpy(char[] dst, int di, char[] src, int si)(Code)



strlen
public static int strlen(char[] a, int start)(Code)



strlen
public static int strlen(char[] a)(Code)



trimToSize
public void trimToSize()(Code)
Each node stores a character (splitchar) which is part of some key(s). In a compressed branch (one that only contain a single string key) the trailer of the key which is not already in nodes is stored externally in the kv array. As items are inserted, key substrings decrease. Some substrings may completely disappear when the whole branch is totally decompressed. The tree is traversed to find the key substrings actually used. In addition, duplicate substrings are removed using a map (implemented with a TernaryTree!).



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.