A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://firefox-source-docs.mozilla.org/xpcom/hashtables_detailed.html below:

Website Navigation


XPCOM Hashtable Technical Details — Firefox Source Docs documentation

XPCOM Hashtable Technical Details

Note

This is a deep-dive into the underlying mechanisms that power the XPCOM hashtables. Some of this information is quite old and may be out of date. If you’re looking for how to use XPCOM hashtables, you should consider reading the XPCOM Hashtable Guide instead.

Mozilla’s Hashtable Implementations

Mozilla has several hashtable implementations, which have been tested and tuned, and hide the inner complexities of hashtable implementations:

PLHashTable

PLHashTable is a part of NSPR. The header file can be found at plhash.h.

There are two situations where PLHashTable may be preferable:

nsTHashtable

To use nsTHashtable, you must declare an entry-class. This entry class contains the key and the data that you are hashing. It also declares functions that manipulate the key. In most cases, the functions of this entry class can be entirely inline. For examples of entry classes, see the declarations at nsHashKeys.h.

The template parameter is the entry class. After construction, use the functions PutEntry/GetEntry/RemoveEntry to alter the hashtable. The Iterator class will do iteration, but beware that the iteration will occur in a seemingly-random order (no sorting).

Before using nsTHashtable, see if nsBaseHashtable and relatives will work for you. They are much easier to use, because you do not have to declare an entry class. If you are hashing a simple key type to a simple data type, they are generally a better choice.

nsBaseHashtable and friends: nsTHashMap, nsInterfaceHashtable, and nsClassHashtable

These C++ templates provide a high-level interface for using hashtables that hides most of the complexities of the underlying implementation. They provide the following features:

nsBaseHashtable is not used directly; choose one of the three derivative classes based on the data type you want to store. The KeyClass is taken from nsHashKeys.h and is the same for all three classes:

The important files to read are nsBaseHashtable.h and nsHashKeys.h. These classes can be used on the stack, as a class member, or on the heap.

Using nsTHashtable as a hash-set

A hash set only tracks the existence of keys: it does not associate data with the keys. This can be done using nsTHashtable<nsSomeHashKey>. The appropriate entries are GetEntry and PutEntry.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.3