Qtopia library API Documentation

QDawg Class Reference

The QDawg class provides an implementation of a Directed Acyclic Word Graph. More...

#include <qdawg.h>

List of all members.

Public Member Functions

 QDawg ()
 ~QDawg ()
bool readFile (const QString &)
bool read (QIODevice *dev)
bool write (QIODevice *dev) const
bool createFromWords (QIODevice *dev)
void createFromWords (const QStringList &)
QStringList allWords () const
bool contains (const QString &) const
int countWords () const
const Noderoot () const
void dump () const

Static Public Attributes

const int nodebits = 18

Friends

class QDawgPrivate


Detailed Description

The QDawg class provides an implementation of a Directed Acyclic Word Graph.

A DAWG provides very fast look-up of words in a word list.

The word list is created using readFile(), read() or createFromWords(). A list of all the DAWG's words is returned by allWords(), and the total number of words is returned by countWords(). Use contains() to see if a particular word is in the DAWG. The root node is returned by root().

A global DAWG is maintained for the current locale. See the Global class for details.

The structure of a DAWG is a graph of Nodes. There are no cycles in the graph (since there are no inifinitely repeating words). Each Node is a member of a list of Nodes called a child list. Each Node in the child list has a letter, an isWord flag, at most one jump arc, and at most one arc to the next child in the list.

If you traverse the Nodes in a DAWG, starting from the root(), and you concatenate all the letters from the single child in each child list that you visit, at every Node which has the isWord flag set your concatenation will be a word in the list represented by the DAWG.

For example, the DAWG below represents the word list: ban, band, can, cane, cans, pan, pane, pans.

This structuring not only provides O(1) lookup of words in the word list, but also produces a smaller storage file than a plain text file word list.

qdawg.png

Definition at line 28 of file qdawg.h.


Constructor & Destructor Documentation

QDawg::QDawg  ) 
 

Constructs a new empty DAWG.

Definition at line 445 of file qdawg.cpp.

QDawg::~QDawg  ) 
 

Deletes the DAWG.

Definition at line 453 of file qdawg.cpp.


Member Function Documentation

bool QDawg::readFile const QString filename  ) 
 

Replaces the DAWG with the DAWG in filename. The file is memory-mapped.

See also:
write()

Definition at line 515 of file qdawg.cpp.

References QFile::encodeName().

Referenced by Global::dawg(), and Global::fixedDawg().

bool QDawg::read QIODevice dev  ) 
 

Replaces the DAWG with the DAWG in dev. The file is memory-mapped.

See also:
write()

Definition at line 541 of file qdawg.cpp.

bool QDawg::write QIODevice dev  )  const
 

Writes the DAWG to dev, in a custom QDAWG format.

Definition at line 555 of file qdawg.cpp.

Referenced by Global::addWords(), and Global::fixedDawg().

bool QDawg::createFromWords QIODevice dev  ) 
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Replaces all the DAWG's words with words read from dev.

Definition at line 462 of file qdawg.cpp.

Referenced by Global::addWords(), and Global::fixedDawg().

void QDawg::createFromWords const QStringList list  ) 
 

Replaces all the DAWG's words with the words in the list.

Definition at line 483 of file qdawg.cpp.

QStringList QDawg::allWords  )  const
 

Returns a list of all the words in the DAWG.

Definition at line 501 of file qdawg.cpp.

Referenced by Global::addWords().

bool QDawg::contains const QString s  )  const
 

Returns TRUE if the DAWG contains the word s; otherwise returns FALSE.

Definition at line 580 of file qdawg.cpp.

int QDawg::countWords  )  const
 

Returns the number of words in the DAWG.

Definition at line 563 of file qdawg.cpp.

const QDawg::Node * QDawg::root  )  const
 

Returns the root Node of the DAWG.

Definition at line 571 of file qdawg.cpp.


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:16 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001