Next: , Previous: Miscellaneous Utility Functions, Up: Top

7 Quarks

a 2-way association between a string and a unique integer identifier.

7.1 Overview

Quarks are associations between strings and integer identifiers. Given either the string or the <g-quark> identifier it is possible to retrieve the other.

Quarks are used for both Datasets and Keyed Data Lists.

To create a new quark from a string, use g-quark-from-string or g-quark-from-static-string.

To find the string corresponding to a given <g-quark>, use g-quark-to-string.

To find the <g-quark> corresponding to a given string, use g-quark-try-string.

Another use for the string pool maintained for the quark functions is string interning, using g-intern-string or g-intern-static-string. An interned string is a canonical representation for a string. One important advantage of interned strings is that they can be compared for equality by a simple pointer comparision, rather than using strcmp.

7.2 Usage

— Function: g-quark-from-string (string mchars) ⇒  (ret unsigned-int)

Gets the <g-quark> identifying the given string. If the string does not currently have an associated <g-quark>, a new <g-quark> is created, using a copy of the string.

a string.
the <g-quark> identifying the string.
— Function: g-quark-to-string (quark unsigned-int) ⇒  (ret mchars)

Gets the string associated with the given <g-quark>.

a <g-quark>.
the string associated with the <g-quark>.
— Function: g-quark-try-string (string mchars) ⇒  (ret unsigned-int)

Gets the <g-quark> associated with the given string, or 0 if the string has no associated <g-quark>.

If you want the GQuark to be created if it doesn't already exist, use g-quark-from-string or g-quark-from-static-string.

a string.
the <g-quark> associated with the string, or 0 if there is no <g-quark> associated with the string.