Supported Operations on Sequences and Sets in Python API for Polyspace
R2026bSeveral properties in the Python® API for Polyspace® are collections that behave like Python sequences or sets.
A sequence is an ordered collection of elements that you can access by position (index). Sequences maintain the order in which you add elements and allow duplicate values. In the Python API for Polyspace, an example of a sequence is the
Definesproperty of apolyspace.project.OwnedBuildConfigurationobject (a list of macro definitions).A set is an unordered collection of unique elements. Sets do not allow duplicates and do not preserve insertion order, but they provide efficient membership testing and set-theoretic operations such as union and intersection. In the Python API for Polyspace, an example of a set is the
ProfilingOptions.FunToIgnoresub-property of aobject (a set of functions to exclude from profiling).polyspace.project.OwnedTestConfiguration
Supported Operations on Sequences
A sequence type supports three tiers of operations depending on whether the type is immutable, assignable, or resizable.
The following tables illustrate these operations using
buildConf.Defines as an example, where buildConf is
an active build configuration obtained from a
project:
proj = polyspace.project.Project("myProject")
buildConf = proj.ActiveBuildConfiguration
defines = buildConf.DefinesRead-Only Operations
All sequence types support the following read-only operations.
| Operation | Example |
|---|---|
| Iteration |
|
| Membership test |
|
| Length |
|
| Index access (integer or slice) | A slice uses the syntax
|
| Find first occurrence | Optional arguments
restrict the search to elements between positions |
| Count occurrences |
|
| Copy to list |
|
| Concatenation |
|
| Minimum and maximum | Strings are ordered lexicographically. |
| Reverse |
|
Assign Operations
In addition to the read-only operations, assignable sequences also support the following operations.
| Operation | Example |
|---|---|
| Item or slice assignment | A slice assignment replaces the
elements selected by |
| In-place reverse |
|
Resize Operations
In addition to the read-only and assign operations, resizable sequences also support the following operations that change the number of elements.
| Operation | Example |
|---|---|
| Remove and return element |
|
| Delete slice | Deletes the elements selected by
|
| Append element |
|
| Extend from another sequence or list |
|
| Insert at index |
|
| Remove first matching element |
|
| Clear all elements |
|
Supported Operations on Sets
Set types support two tiers of operations depending on whether they are immutable or mutable.
The following tables illustrate these operations using ignoredFuns as
an example, where ignoredFuns is a set of function names to exclude from
profiling:
proj = polyspace.project.Project("myProject")
testConf = proj.ActiveTestConfiguration
ignoredFuns = testConf.ProfilingOptions.FunToIgnoreRead-Only Operations
All set types support the following read-only operations.
| Operation | Example |
|---|---|
| Iteration |
|
| Length |
|
| Membership test |
|
| Disjoint test |
|
| Subset test |
|
| Superset test |
|
| Union |
|
| Intersection |
|
| Difference |
|
| Symmetric difference |
|
| Copy |
|
Mutation Operations
In addition to the read-only operations, mutable sets also support the following operations that modify the set contents.
| Operation | Example |
|---|---|
| Update (union in place) |
|
| Intersection in place |
|
| Difference in place |
|
| Symmetric difference in place |
|
| Add element |
|
| Remove element (raises error if missing) |
|
| Discard element (no error if missing) |
|
| Clear all elements |
|