"StringVector" (Data Structure)

"StringVector"

represents a vector of strings.

Details

  • A "StringVector" is an efficient immutable representation of a list or vector of strings.
  • CreateDataStructure["StringVector",{s1,}]create a new "StringVector" from a list of strings
    Typed[x,"StringVector"]give x the type "StringVector"
  • For a data structure of type "StringVector", the following operations can be used:
  • ds["Part",i]give the i^(th) part of dstime: O(1)
    ds["Pick",bvec]pick the elements of ds corresponding to the set bits of the "BitVector" bvectime: O(n)
    ds["Join",ds1]join the vectors ds and ds1time: O(n)
    ds["StringByteCount"]give StringByteCount for each string element in dstime: O(n)
    ds["StringLength"]give StringLength for each string element in dstime: O(n)
    ds["StringCount",patt]give StringCount for each element of ds for the general string expression patttime: O(n)
    ds["StringMatchQ",patt]return a "BitVector" with bit i set for each element si of ds for which StringMatchQ[si,patt] is Truetime: O(n)
    ds["StringFreeQ",patt]return a "BitVector" with bit i set for each element si of ds for which StringFreeQ[si,patt] is Truetime: O(n)
    ds["StringContainsQ",patt]return a "BitVector" with bit i set for each element si of ds for which StringContainsQ[si,patt] is Truetime: O(n)
    ds["StringStartsQ",patt]return a "BitVector" with bit i set for each element si of ds for which StringStartsQ[si,patt] is Truetime: O(n)
    ds["StringEndsQ",patt]return a "BitVector" with bit i set for each element si of ds for which StringEndsQ[si,patt] is Truetime: O(n)
    ds["Visualization"]return a visualization of dstime: O(n)
  • The following functions are also supported:
  • dsi===dsjTrue, if dsi equals dsj
    FullForm[ds]full form of ds
    Information[ds]information about ds
    InputForm[ds]input form of ds
    Normal[ds]convert ds to a normal expression

Examples

open allclose all

Basic Examples  (4)

A new "StringVector" can be created with CreateDataStructure:

Get the third element as a string:

Get the last three elements in reverse order as a "StringVector":

Change the result to a list of strings:

Get the string length for each element:

Get the string byte count for each element:

Count the number of English vowels in each element:

Determine which elements have the letter "a":

Pick those elements:

Select the elements do not have the letter "e":

"StringVector" will typically use less memory than a list of strings:

Lookup of a literal string can be much faster with "StringVector" than for a list of strings:

Selecting elements can be much faster with "StringVector" than for a list of strings:

Select the "StringVector" elements that start with "r" and end with "e":

Use Select with the list of strings:

The selection is the same:

Scope  (1)

Information  (1)

A new "StringVector" can be created with CreateDataStructure:

Information about the data structure ds: