"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 part of ds time: O(1) ds["Pick",bvec] pick the elements of ds corresponding to the set bits of the "BitVector" bvec time: O(n) ds["Join",ds1] join the vectors ds and ds1 time: O(n) ds["StringByteCount"] give StringByteCount for each string element in ds time: O(n) ds["StringLength"] give StringLength for each string element in ds time: O(n) ds["StringCount",patt] give StringCount for each element of ds for the general string expression patt time: O(n) ds["StringMatchQ",patt] return a "BitVector" with bit i set for each element si of ds for which StringMatchQ[si,patt] is True time: O(n) ds["StringFreeQ",patt] return a "BitVector" with bit i set for each element si of ds for which StringFreeQ[si,patt] is True time: O(n) ds["StringContainsQ",patt] return a "BitVector" with bit i set for each element si of ds for which StringContainsQ[si,patt] is True time: O(n) ds["StringStartsQ",patt] return a "BitVector" with bit i set for each element si of ds for which StringStartsQ[si,patt] is True time: O(n) ds["StringEndsQ",patt] return a "BitVector" with bit i set for each element si of ds for which StringEndsQ[si,patt] is True time: O(n) ds["Visualization"] return a visualization of ds time: O(n) - The following functions are also supported:
-
dsi===dsj True, 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 allBasic 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":
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:
Scope (1)
Information (1)
A new "StringVector" can be created with CreateDataStructure: