structs.StringSet Extends
Creates a set of strings.

Inheritance

Constructor

goog.structs.StringSet(opt_elements)

Parameters

opt_elements : !Array=
Elements to add to the set. The non-string items will be converted to strings, so 15 and '15' will mean the same.

Instance Methods

Public Protected Private
__iterator__(opt_keys) !goog.iter.Iterator
Returns an iterator that iterates over the elements in the set. NOTE: creating the iterator copies the whole set so use #forEach when possible.
Arguments:
opt_keys : boolean=
Ignored for sets.
Returns: !goog.iter.Iterator  An iterator over the elements in the set.
code »
add(element)
Adds a single element to the set.
Arguments:
element : *
The element to add. It will be converted to string.
code »
addArray(arr)
Adds a the elements of an array to this set.
Arguments:
arr : !Array
The array to add the elements of.
code »
addDifference_(set1set2)
Adds the elements which are in set1 but not in set2 to this set.
Arguments:
set1 : !goog.structs.StringSet
First set.
set2 : !goog.structs.StringSet
Second set.
code »
addSet(stringSet)
Adds a the elements of a set to this set.
Arguments:
stringSet : !goog.structs.StringSet
The set to add the elements of.
code »
clear()
Removes all elements of the set.
code »
clone() !goog.structs.StringSet
No description.
Returns: !goog.structs.StringSet  Clone of the set.
code »
contains(element) boolean
Tells if the set contains the given element.
Arguments:
element : *
The element to check.
Returns: boolean  Whether it is in the set.
code »
containsArray(arr) boolean
Tells if the set contains all elements of the array.
Arguments:
arr : !Array
The elements to check.
Returns: boolean  Whether they are in the set.
code »
equals(stringSet) boolean
Tells if this set has the same elements as the given set.
Arguments:
stringSet : !goog.structs.StringSet
The other set.
Returns: boolean  Whether they have the same elements.
code »
forEach(fopt_obj)
Calls a function for each element in the set.
Arguments:
f : function(string, undefined, !goog.structs.StringSet)
The function to call for every element. It takes the element, undefined (because sets have no notion of keys), and the set.
opt_obj : Object=
The object to be used as the value of 'this' within f.
code »
getCount() number
Counts the number of elements in the set in linear time. NOTE: getCount is always called at most once per set instance in google3. If this usage pattern won't change, the linear getCount implementation is better, because
  • populating a set and getting the number of elements in it takes the same amount of time as keeping a count_ member up to date and getting its value;
  • if getCount is not called, adding and removing elements have no overhead.
  • Returns: number  The number of elements in the set.
    code »
    getDifference(stringSet) !goog.structs.StringSet
    Calculates the difference of two sets.
    Arguments:
    stringSet : !goog.structs.StringSet
    The set to subtract from this set.
    Returns: !goog.structs.StringSet  this minus stringSet.
    code »
    getIntersection(stringSet) !goog.structs.StringSet
    Calculates the intersection of this set with another set.
    Arguments:
    stringSet : !goog.structs.StringSet
    The set to take the intersection with.
    Returns: !goog.structs.StringSet  A new set with the common elements.
    code »
    getSymmetricDifference(stringSet) !goog.structs.StringSet
    Calculates the symmetric difference of two sets.
    Arguments:
    stringSet : !goog.structs.StringSet
    The other set.
    Returns: !goog.structs.StringSet  A new set with the elements in exactly one of this and stringSet.
    code »
    getUnion(stringSet) !goog.structs.StringSet
    Calculates the union of this set and another set.
    Arguments:
    stringSet : !goog.structs.StringSet
    The set to take the union with.
    Returns: !goog.structs.StringSet  A new set with the union of elements.
    code »
    getValues() !Array.<string>
    No description.
    Returns: !Array.<string>  The elements of the set.
    code »
    isDisjoint(stringSet) boolean
    Tells if this set and the given set are disjoint.
    Arguments:
    stringSet : !goog.structs.StringSet
    The other set.
    Returns: boolean  True iff they don't have common elements.
    code »
    isEmpty() boolean
    No description.
    Returns: boolean  Whether the set is empty.
    code »
    isSubsetOf(stringSet) boolean
    Tells if this set is the subset of the given set.
    Arguments:
    stringSet : !goog.structs.StringSet
    The other set.
    Returns: boolean  Whether this set if the subset of that.
    code »
    isSupersetOf(stringSet) boolean
    Tells if this set is the superset of the given set.
    Arguments:
    stringSet : !goog.structs.StringSet
    The other set.
    Returns: boolean  Whether this set if the superset of that.
    code »
    remove(element) boolean
    Removes a single element from the set.
    Arguments:
    element : *
    The element to remove.
    Returns: boolean  Whether the element was in the set.
    code »
    removeArray(arr)
    Removes all elements of the given array from this set.
    Arguments:
    arr : !Array
    The elements to remove.
    code »
    removeSet(stringSet)
    Removes all elements of the given set from this set.
    Arguments:
    stringSet : !goog.structs.StringSet
    The set of elements to remove.
    code »

    Instance Properties

    elements_ :
    An object storing the escaped elements of the set in its keys.
    Code »

    Static Methods

    goog.structs.StringSet.decode_(key) string
    Inverse function of goog.structs.StringSet.encode_. NOTE: forEach would be 30% faster in FF if the compiler inlined decode.
    Arguments:
    key : string
    The escaped element used as the key of the internal object.
    Returns: string  The unescaped element.
    code »
    goog.structs.StringSet.encode_(element) *
    The '__proto__' and the '__count__' keys aren't enumerable in Firefox, and 'toString', 'valueOf', 'constructor', etc. aren't enumerable in IE so they have to be escaped before they are added to the internal object. NOTE: When a new set is created, 50-80% of the CPU time is spent in encode.
    Arguments:
    element : *
    The element to escape.
    Returns: *  The escaped element or the element itself if it doesn't have to be escaped.
    code »

    Static Properties

    goog.structs.StringSet.EMPTY_OBJECT_ :
    Empty object. Referring to it is faster than creating a new empty object in goog.structs.StringSet.encode_.
    Code »

    Package structs

    Package Reference