diff options
| author | Camille Mougey <camille.mougey@cea.fr> | 2015-02-18 13:18:00 +0100 |
|---|---|---|
| committer | Camille Mougey <camille.mougey@cea.fr> | 2015-02-18 15:49:36 +0100 |
| commit | 797e95f5385fea24f0e1f3699ee277d33ae97984 (patch) | |
| tree | e251b879eb3ef477b557ee6f9104a41244b0a630 /miasm2/core/interval.py | |
| parent | fae4d7fca6b91da8fb934470c4307a37c4349dd1 (diff) | |
| download | miasm-797e95f5385fea24f0e1f3699ee277d33ae97984.tar.gz miasm-797e95f5385fea24f0e1f3699ee277d33ae97984.zip | |
Core/Interval: PyLint pass
Diffstat (limited to 'miasm2/core/interval.py')
| -rw-r--r-- | miasm2/core/interval.py | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/miasm2/core/interval.py b/miasm2/core/interval.py index cd2a793e..8a6c1991 100644 --- a/miasm2/core/interval.py +++ b/miasm2/core/interval.py @@ -15,32 +15,37 @@ INT_JOIN_BA = 5 # 5 => join b,a touch -def cmp_interval(a, b): - if a == b: +def cmp_interval(inter1, inter2): + """Compare @inter1 and @inter2 and returns the associated INT_* case + @inter1, @inter2: interval instance + """ + if inter1 == inter2: return INT_EQ - a1, a2 = a - b1, b2 = b - if a1 <= b1 and a2 >= b2: - return INT_B_IN_A - if b1 <= a1 and b2 >= a2: - return INT_A_IN_B - if a2 + 1 == b1: - return INT_JOIN_AB - if b2 + 1 == a1: - return INT_JOIN_BA - if a1 > b2 + 1 or b1 > a2 + 1: - return INT_DISJOIN - return INT_JOIN + + inter1_start, inter1_stop = inter1 + inter2_start, inter2_stop = inter2 + result = INT_JOIN + if inter1_start <= inter2_start and inter1_stop >= inter2_stop: + result = INT_B_IN_A + if inter2_start <= inter1_start and inter2_stop >= inter1_stop: + result = INT_A_IN_B + if inter1_stop + 1 == inter2_start: + result = INT_JOIN_AB + if inter2_stop + 1 == inter1_start: + result = INT_JOIN_BA + if inter1_start > inter2_stop + 1 or inter2_start > inter1_stop + 1: + result = INT_DISJOIN + return result # interval is: [a, b] -class interval: +class interval(object): def __init__(self, a=None): if a is None: a = [] - if isinstance(a, interval): + elif isinstance(a, interval): a = a.intervals self.is_cannon = False self.intervals = a @@ -130,12 +135,12 @@ class interval: i += 1 x = to_test[i] if x[0] > x[1]: - del(to_test[i]) + del to_test[i] i -= 1 continue while to_del and to_del[0][1] < x[0]: - del(to_del[0]) + del to_del[0] for y in to_del: if y[0] > x[1]: @@ -144,15 +149,15 @@ class interval: if rez == INT_DISJOIN: continue elif rez == INT_EQ: - del(to_test[i]) + del to_test[i] i -= 1 break elif rez == INT_A_IN_B: - del(to_test[i]) + del to_test[i] i -= 1 break elif rez == INT_B_IN_A: - del(to_test[i]) + del to_test[i] i1 = (x[0], y[0] - 1) i2 = (y[1] + 1, x[1]) to_test[i:i] = [i1, i2] @@ -161,7 +166,7 @@ class interval: elif rez in [INT_JOIN_AB, INT_JOIN_BA]: continue elif rez == INT_JOIN: - del(to_test[i]) + del to_test[i] if x[0] < y[0]: to_test[i:i] = [(x[0], y[0] - 1)] else: |