class int_pair_set¶
Used to store pairs of integers, each of which represents a range of locations in a source file.
Each pair (a, b) in an int_pair_set represents a substring in a source file as follows:
| integer | represents | constraints |
|---|---|---|
| a (first) | offset from the beginning of the file (0 origin) | must be between 0 and 2^24-1 |
| b (second) | one less than the length of the substring | must be non-negative |
The implementation may split a given pair into two or more pairs that represent the same interval.
The following are useful for retrieving int_pair_set values.
| Class | Methods |
|---|---|
point |
point.charpos() |
point_set |
point_set.to_int_pair_set_in_sfileinst() |
Use a int_pair_set_iterator to iterate over a int_pair_set . For example:
for e in my_int_pair_set:
print('int_pair: ', e)
int_pair_set Members¶
| Constructor | __init__() |
| Methods | __contains__(), __eq__(), __hash__(), __iter__(), __len__(), __ne__(), __repr__(), __str__(), add(), clear(), difference(), discard(), empty(), intersect(), kind(), remove(), to_point_set(), to_vector(), union(), union_p() |
int_pair_set Details¶
-
class
cs.int_pair_set¶ Used to store pairs of integers, each of which represents a range of locations in a source file.
-
__init__()¶ Construct an empty set.
>>> int_pair_set() <cs.int_pair_set {}>
-
__init__(other)¶ Copy constructor.
Parameters: other ( int_pair_set) –>>> v0 = int_pair_set([(134217728, 5)]) >>> int_pair_set(v0) <cs.int_pair_set {(134217728, 5)}>
-
__init__(v)¶ Construct a set from a list of elements.
Parameters: v (iterable of (int, int)) – The set elements. >>> int_pair_set([(3829380143, 188)]) <cs.int_pair_set {(3829380143, 188)}>
-
__init__(k)¶ Construct an empty set of the specified kind.
Parameters: k ( set_kind) – The set kind.Raises: result.ERROR_CODESURFER_ONLYif k isset_kind.TRIE, which is only available in CodeSurfer.>>> int_pair_set(set_kind.TRIE) <cs.int_pair_set {}>
-
__contains__(elt)¶ Check: does the set contain the specified element?
Parameters: elt ((int, int)) – The element to check. Return type: bool Returns: Trueifeltis present in the set,Falseotherwise.Raises: OverflowError>>> v0 = int_pair_set() >>> (4294967294, 84) in v0 False
-
__eq__(__y)¶ Equality operator for
int_pair_set.Parameters: __y ( int_pair_set) – The set to compare against.Return type: bool Returns: Trueifselfequal to__y,Falseotherwise.>>> v0 = int_pair_set() >>> v1 = int_pair_set() >>> v1 == v0 True
-
__hash__()¶ Get a hash of the set.
Return type: int Returns: The hash value for the set. >>> v0 = int_pair_set() >>> hash(v0) 0
-
__iter__()¶ Get an iterator over the set elements.
Return type: int_pair_set_iteratorReturns: An iterator over the set elements. >>> v0 = int_pair_set([(3829380143, 188)]) >>> iter(v0) <cs.int_pair_set_iterator begin>
-
__len__()¶ Get the set cardinality.
Return type: int Returns: The number of elements in the set. >>> v0 = int_pair_set() >>> len(v0) 0L
-
__ne__(__y)¶ Inequality operator for
int_pair_set.Parameters: __y ( int_pair_set) – The set to compare against.Return type: bool Returns: Falseifselfequal to__yaccording toint_pair_set.__eq__(),Trueotherwise.>>> v0 = int_pair_set(set_kind.TRIE) >>> v1 = int_pair_set() >>> v2 = int_pair_set(v1) >>> v2 != v0 False
-
__repr__()¶ Get a representation of a set object that includes information useful for debugging.
Return type: str >>> v0 = int_pair_set() >>> repr(v0) '<cs.int_pair_set {}>'
-
__str__()¶ Get a simple string representation of a set object.
Return type: str >>> v0 = int_pair_set() >>> str(v0) '{}'
-
add(v)¶ Add an element to the set.
Parameters: v ((int, int)) – The element to add. Return type: bool Returns: Trueifvwas not already present in the set,Falseif it was already present.Raises: OverflowError- Side effects: Modifies
self.
>>> v0 = int_pair_set() >>> v0.add((1, 791)) True >>> v0 <cs.int_pair_set {(1, 791)}>
- Side effects: Modifies
-
clear()¶ Remove all elements from the set (that is, make it empty).
Return type: NoneType - Side effects: Modifies
self.
>>> v0 = int_pair_set() >>> v0.add((1, 791)) True >>> v0 <cs.int_pair_set {(1, 791)}> >>> v0.clear() >>> v1 <cs.int_pair_set {}>
- Side effects: Modifies
-
difference(b)¶ Set difference.
Parameters: b ( int_pair_set) – The set to subtract fromself.Return type: int_pair_setReturns: A set containing self-b.The returned set contains the elements in
selfthat are not inb.>>> from functools import reduce >>> cu = next(c for c in project.current().compunits() if c.name().endswith('apitest.cpp')) >>> proc =next(p for p in cu.procedures() if p.name()=='bar') >>> all_formalin_pos = reduce(lambda setA,setB: setA.union(setB), ... [fin.charpos()[1] for fin in proc.formal_ins()]) >>> all_formalin_pos <cs.int_pair_set {(124, 4), (131, 3), (137, 0), 1 more...}> >>> >>> first_formalin_pos = proc.formal_ins_vector()[0].charpos()[1] >>> first_formalin_pos <cs.int_pair_set {(124, 4)}> >>> >>> all_formalin_pos.difference(first_formalin_pos) <cs.int_pair_set {(131, 3), (137, 0), (140, 4)}>
-
discard(v)¶ Remove an element from the set.
Parameters: v ((int, int)) – The element to remove. Return type: NoneType Returns: The number of elements deleted: - 1 if
vwas present in the set. - 0 if
vwas not present in the set.
Raises: OverflowError- Side effects: Modifies
self.
>>> ips = int_pair_set([(131, 3), (137, 0), (140, 4)]) >>> ips <cs.int_pair_set {(131, 3), (137, 0), (140, 4)}> >>> ips.discard((137,0)) >>> ips <cs.int_pair_set {(131, 3), (140, 4)}>
- 1 if
-
empty()¶ Check: is the set empty?
Return type: bool Returns: Trueif the set is empty,Falseotherwise.>>> ips = int_pair_set([(131, 3), (137, 0), (140, 4)]) >>> ips.empty() False >>> ips.clear() >>> ips.empty() True
-
intersect(b)¶ Set intersection.
Parameters: b ( int_pair_set) – The other operand for the intersection operation.Return type: int_pair_setReturns: A set containing selfINTERSECTb.The returned set contains the elements that are in both
selfandb.>>> ips1 = int_pair_set([(131, 3), (137, 0), (140, 4)]) >>> ips2 = int_pair_set([(140, 4), (140, 5)]) >>> ips1.intersect(ips2) <cs.int_pair_set {(140, 4)}>
-
kind()¶ Get the kind of a set.
Return type: set_kindReturns: The set kind ( set_kind).Raises: result.ELEMENT_NOT_PRESENTif the set was constructed with the default constructor and no elements have been added yet.>>> v0 = int_pair_set(set_kind.TRIE) >>> v0.kind() <cs.set_kind fast-vector>
-
remove(v)¶ Remove an element from the set.
Parameters: v ((int, int)) – The element to remove. Return type: NoneType Raises: OverflowError- Side effects: Modifies
self.
>>> ips = int_pair_set([(131, 3), (137, 0), (140, 4)]) >>> ips <cs.int_pair_set {(131, 3), (137, 0), (140, 4)}> >>> ips.discard((137,0)) >>> ips <cs.int_pair_set {(131, 3), (140, 4)}>
- Side effects: Modifies
-
to_point_set(sfi)¶ Get the
point_setassociated with anint_pair_set.Parameters: sfi ( sfileinst) – The source file instance for which theint_pair_setcontains file positions.Return type: point_setReturns: A new point_setcontaining the points corresponding to the locations given byselfin the file identified bysfi.>>> from functools import reduce >>> cu = next(c for c in project.current().compunits() if c.name().endswith('apitest.cpp')) >>> proc = next(p for p in cu.procedures() if p.name()=='bar') >>> all_formalin_pos = reduce(lambda setA,setB: setA.union(setB), ... [fin.charpos()[1] for fin in proc.formal_ins()]) >>> >>> all_formalin_pos <cs.int_pair_set {(124, 4), (131, 3), (137, 0), 1 more...}> >>> >>> all_formalin_pos.to_point_set(proc.file_line()[0]) <cs.point_set {<cs.point [formal-in] >, <cs.point [formal-in] >, <cs.point [formal-in] >}>
-
to_vector()¶ Get a list of all the elements in the set.
Return type: [(int, int)] Returns: A list containing all the elements in the set. >>> v0 = int_pair_set([(101, 20280)]) >>> v0.to_vector() ((101, 20280),)
-
union(b)¶ Set union.
Parameters: b ( int_pair_set) – The other operand for the union operation.Return type: int_pair_setReturns: A set containing selfUNIONb.The returned set contains the elements that are in
self,b, or both.>>> ips1 = int_pair_set([(1,2), (3,4)]) >>> ips2 = int_pair_set([(5,6), (7,8)]) >>> ips1.union(ips2) <cs.int_pair_set {(1, 2), (3, 4), (5, 6), 1 more...}>
-
union_p(b)¶ Update a set to the union of itself and another set.
Parameters: b ( int_pair_set) – The set whose elements are to be added.Return type: NoneType - Side effects: Modifies
self.
selfis updated to containselfUNIONb.>>> ips1 = int_pair_set([(1,2), (3,4)]) >>> ips2 = int_pair_set([(5,6), (7,8)]) >>> ips1.union_p(ips2) >>> ips1 <cs.int_pair_set {(1, 2), (3, 4), (5, 6), 1 more...}>
- Side effects: Modifies
-