Trie Class | Extending Qt Creator Manual

Extending Qt Creator Manual | Trie

Extending Qt Creator Manual 4.4.1

# Trie Class

(QmlJS::PersistentTrie::Trie)

The Trie class implements a trie that is persistent (not on disk but in memory). More...

Header: | #include <Trie>

- List of all members, including inherited members

## Public Functions

| Trie()
| Trie(const TrieNode::Ptr &t)
| Trie(const Trie &o)
QStringList | complete(const QString &root, const QString &base = QString(), LookupFlags flags = LookupFlags( CaseInsensitive | Partial )) const
bool | contains(const QString &value, LookupFlags flags = LookupFlags( 0 )) const
void | insert(const QString &value)
Trie | insertF(const QString &value) const
void | intersect(const Trie &v)
Trie | intersectF(const Trie &v) const
bool | isEmpty() const
void | merge(const Trie &v)
Trie | mergeF(const Trie &v) const
void | replace(const QHash<QString, QString> &replacements)
Trie | replaceF(const QHash<QString, QString> &replacements) const
QStringList | stringList() const
bool | operator!=(const Trie &o)
bool | operator==(const Trie &o)

## Detailed Description

The Trie class implements a trie that is persistent (not on disk but in memory).

This means that several versions can coexist, as adding an element is non-destructive, and as much as possible is shared.

The trie is only partially ordered. It preserves the order of the inserted elements as much as possible. This makes some operations a bit slower, but is considered a feature. This means the order in which you insert the elements matters.

An important use case for this is completions, and several strategies are available. Results order can be improved by using the matching strength.

All const operations are threadsafe, and copy is cheap (only a QSharedPointer copy).

Assigning a shared pointer is not threadsafe, so updating the head is not threadsafe, and should be done only on a local instance (shared pointer used only from a single thread), or protected with locks.

This is a two-level implementation, based on a fully functional implementation (PersistentTrie::Trie), which could be private but was left public because deemed useful.

Would gain from some memory optimization, or direct string implementation.

## Member Function Documentation

### Trie::Trie()

Default constructs an instance of Trie.

### Trie::Trie(const TrieNode::Ptr &t)

Copy constructor.

### Trie::Trie(const Trie &o)

Copy constructor.

### QStringList Trie::complete(const QString &root, const QString &base = QString(), LookupFlags flags = LookupFlags( CaseInsensitive | Partial )) const

### bool Trie::contains(const QString &value, LookupFlags flags = LookupFlags( 0 )) const

### void Trie::insert(const QString &value)

Inserts into the current trie.

Non threadsafe. Only use this function on an instance that is used only in a single thread, or that is protected by locks.

### Trie Trie::insertF(const QString &value) const

### void Trie::intersect(const Trie &v)

Intersects into the current trie.

Non threadsafe. Only use this function on an instance that is used only in a single thread, or that is protected by locks.

### Trie Trie::intersectF(const Trie &v) const

### bool Trie::isEmpty() const

### void Trie::merge(const Trie &v)

Merges the given trie into the current one.

Non threadsafe. Only use this function on an instance that is used only in a single thread, or that is protected by locks.

### Trie Trie::mergeF(const Trie &v) const

### void Trie::replace(const QHash<QString, QString> &replacements)

### Trie Trie::replaceF(const QHash<QString, QString> &replacements) const

### QStringList Trie::stringList() const

### bool Trie::operator!=(const Trie &o)

### bool Trie::operator==(const Trie &o)