| Home | Trees | Index | Help |
|
|---|
| Package WordUtils :: Module tree :: Class TernarySearchTree |
|
object --+
|
TernarySearchTree
| Method Summary | |
|---|---|
Default constructor. | |
Adds a key (word) to an existing tree. | |
Compresses a tree, optionally returning compression ratio. | |
Returns a sorted list representation of the tree. | |
Reads a wordlist or database file into a tree. | |
Reads a Python list into a tree. | |
Searches for a pattern in a tree. | |
Removes a key (word) from a tree. | |
Writes a tree to disk as a wordlist and/or in a portable "database" format. | |
Searches for a complete string in a tree. | |
Traverses a tree and executes func(word) for each
word. | |
_disk_patternSearch(self,
filepath,
pattern,
word)
| |
_disk_patternSearch_r(self,
f,
fp,
pattern,
word)
| |
_disk_saveDatabase(self,
db,
newdb)
| |
_disk_search(self,
filepath,
key)
| |
_disk_traverse(self,
filepath,
word,
func)
| |
_disk_traverse_r(self,
file,
fp,
word,
func)
| |
Property target used to get db. | |
Property target used to get root. | |
Property target used to get type. | |
Property target used to get wl. | |
_insert(self,
node,
key)
| |
_mem_insert(self,
node,
key)
| |
_mem_loadFileDatabase(self,
db)
| |
_mem_loadFileDatabase_r(self,
node,
file,
fp)
| |
_mem_loadFileWordlist(self,
wl)
| |
_mem_loadList(self,
list)
| |
_mem_patternSearch(self,
node,
pattern,
word)
| |
_mem_saveDatabase(self,
node,
newdb)
| |
_mem_saveDatabase_r(self,
node,
f)
| |
_mem_search(self,
node,
key)
| |
_mem_traverse(self,
node,
word,
func)
| |
_saveDatabase(self,
root,
db,
newdb,
overwrite)
| |
_saveWordlist(self,
newwl,
overwrite)
| |
| Inherited from object | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
x.__hash__() <==> hash(x) | |
T.__new__(S, ...) -> a new object with type S, a subtype of T | |
helper for pickle | |
helper for pickle | |
x.__repr__() <==> repr(x) | |
x.__setattr__('name', value) <==> x.name = value | |
x.__str__() <==> str(x) | |
| Property Summary | |
|---|---|
db: Location of database on disk. | |
root: Root node of tree. | |
type: Tree type (IN_MEMORY or ON_DISK). | |
wl: Location of wordlist on disk. | |
| Method Details |
|---|
__init__(self,
type=0,
db=None,
wl=None)
|
add(self, key)Adds a key (word) to an existing tree. This function inserts into a tree by building a list of the words in the tree, inserting the new key into the list, and then re-building the tree based on the new list. Obviously, this is rather memory intensive and inefficient. The whole point of using a tree in the first place is to avoid having a list of words around. However, I haven't found any other good way to do this. You may not really need this functionality. Normally, a tree would be filled using theloadFile method. This add method would only be used to add a
new word to an existing tree. If you only need to add a few words to an
existing tree, consider whether you might be better off keeping around
a small Python list or dictionary to hold the extra word, instead of
adding to the tree.
|
compress(self, ratio=False)Compresses a tree, optionally returning compression ratio. This method may only be used on
|
list(self)Returns a sorted list representation of the tree.
|
loadFile(self, db=None, wl=None)Reads a wordlist or database file into a tree. Either a database or a wordlist may be used, but not both. If a wordlist is used, it is assumed to be properly sorted on disk (i.e. the words must be in alphabetical order). Neither file will ever be written to. Calling this function on a tree that has been previously initialized will overwrite the contents of that tree. You may not choose to load a wordlist into anON_DISK
tree. First, create an IN_MEMORY tree using the wordlist.
Then, save the IN_MEMORY tree as a database. Then, you can
load use the database on disk as the source for your
ON_DISK tree.
|
loadList(self, list)Reads a Python list into a tree. Calling this function on a tree that has been previously initialized will overwrite the contents of that tree. You may only load a list into anIN_MEMORY tree. If you
need the list in an on-disk tree, create an IN_MEMORY tree
using the list. Then, save the IN_MEMORY tree as a
database. Then, you can load the database on disk as the source for
your ON_DISK tree.
|
patternSearch(self, pattern)Searches for a pattern in a tree. A pattern uses the. (period) character to represent a
wildcard. So, for instance, the pattern '.ai.' would match
the words 'rail', 'hail',
'mail', etc. if those words were in the tree.
|
remove(self, key)Removes a key (word) from a tree. This function removes a word from a tree by building a list of the words in the tree, removing the key from the list, and then re-building the tree based on the new list. Obviously, this is rather memory intensive and inefficient. The whole point of using a tree in the first place is to avoid having a list of words around. However, I haven't found any other good way to do this. You may not really need this functionality. If you only need to remove a few words from an existing tree, consider whether you might be better off just keeping around a small Python list or dictionary to hold those words. You could then use the list or dictionary to validate the results returned from thepatternSearch method.
|
save(self, db=None, wl=None, overwrite=False)Writes a tree to disk as a wordlist and/or in a portable "database" format. Both the ON_DISK, then this
method cannot be used to overwrite the in-use database on disk.
|
search(self, key)Searches for a complete string in a tree.
|
traverse(self, func=None)Traverses a tree and executes
lambda x: sys.stdout.write("%s\n" % x)
which will print out each word on its own line (the words will be
unordered).
|
_getDb(self)Property target used to get db. |
_getRoot(self)Property target used to get root. |
_getType(self)Property target used to get type. |
_getWl(self)Property target used to get wl. |
| Property Details |
|---|
dbLocation of database on disk.
|
rootRoot node of tree.
|
typeTree type (IN_MEMORY or ON_DISK).
|
wlLocation of wordlist on disk.
|
| Home | Trees | Index | Help |
|
|---|
| Generated by Epydoc 2.1 on Tue Sep 27 17:02:10 2005 | http://epydoc.sf.net |