summaryrefslogtreecommitdiffstats
path: root/xpcom/docs/collections.rst
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /xpcom/docs/collections.rst
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xpcom/docs/collections.rst')
-rw-r--r--xpcom/docs/collections.rst95
1 files changed, 95 insertions, 0 deletions
diff --git a/xpcom/docs/collections.rst b/xpcom/docs/collections.rst
new file mode 100644
index 0000000000..b4075fda9b
--- /dev/null
+++ b/xpcom/docs/collections.rst
@@ -0,0 +1,95 @@
+XPCOM Collections
+=================
+
+``nsTArray`` and ``AutoTArray``
+-------------------------------
+
+``nsTArray<T>`` is a typesafe array for holding various objects.
+
+Rust Bindings
+~~~~~~~~~~~~~
+
+When the ``thin_vec`` crate is built in Gecko, ``thin_vec::ThinVec<T>`` is
+guaranteed to have the same memory layout and allocation strategy as
+``nsTArray``, meaning that the two types may be used interchangeably across
+FFI boundaries. The type is **not** safe to pass by-value over FFI
+boundaries, due to Rust and C++ differing in when they run destructors.
+
+The element type ``T`` must be memory-compatible with both Rust and C++ code
+to use over FFI.
+
+``nsTHashMap`` and ``nsTHashSet``
+---------------------------------
+
+These types are the recommended interface for writing new XPCOM hashmaps and
+hashsets in XPCOM code.
+
+Supported Hash Keys
+~~~~~~~~~~~~~~~~~~~
+
+The following types are supported as the key parameter to ``nsTHashMap`` and
+``nsTHashSet``.
+
+========================== ======================
+Type Hash Key
+========================== ======================
+``T*`` ``nsPtrHashKey<T>``
+``T*`` ``nsPtrHashKey<T>``
+``nsCString`` ``nsCStringHashKey``
+``nsString`` ``nsStringHashKey``
+``uint32_t`` ``nsUint32HashKey``
+``uint64_t`` ``nsUint64HashKey``
+``intptr_t`` ``IntPtrHashKey``
+``nsCOMPtr<nsISupports>`` ``nsISupportsHashKey``
+``RefPtr<T>`` ``nsRefPtrHashKey<T>``
+``nsID`` ``nsIDHashKey``
+========================== ======================
+
+Any key not in this list must inherit from the ``PLDHashEntryHdr`` class to
+implement manual hashing behaviour.
+
+Class Reference
+~~~~~~~~~~~~~~~
+
+.. note::
+
+ The ``nsTHashMap`` and ``nsTHashSet`` types are not declared exactly like
+ this in code. This is intended largely as a practical reference.
+
+.. cpp:class:: template<K, V> nsTHashMap<K, V>
+
+ The ``nsTHashMap<K, V>`` class is currently defined as a thin type alias
+ around ``nsBaseHashtable``. See the methods defined on that class for
+ more detailed documentation.
+
+ https://searchfox.org/mozilla-central/source/xpcom/ds/nsBaseHashtable.h
+
+ .. cpp:function:: uint32_t Count() const
+
+ .. cpp:function:: bool IsEmpty() const
+
+ .. cpp:function:: bool Get(KeyType aKey, V* aData) const
+
+ Get the value, returning a flag indicating the presence of the entry
+ in the table.
+
+ .. cpp:function:: V Get(KeyType aKey) const
+
+ Get the value, returning a default-initialized object if the entry is
+ not present in the table.
+
+ .. cpp:function:: Maybe<V> MaybeGet(KeyType aKey) const
+
+ Get the value, returning Nothing if the entry is not present in the table.
+
+ .. cpp:function:: V& LookupOrInsert(KeyType aKey, Args&&... aArgs) const
+
+ .. cpp:function:: V& LookupOrInsertWith(KeyType aKey, F&& aFunc) const
+
+.. cpp:class:: template<K> nsTHashSet<K>
+
+ The ``nsTHashSet<K>`` class is currently defined as a thin type alias
+ around ``nsTBaseHashSet``. See the methods defined on that class for
+ more detailed documentation.
+
+ https://searchfox.org/mozilla-central/source/xpcom/ds/nsTHashSet.h