mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-10-01 01:26:08 -04:00
remove operation for dart VeilidSubkeyRange and List<>
This commit is contained in:
parent
d74dad3ec9
commit
a32774a29c
@ -141,10 +141,37 @@ class ValueSubkeyRange with _$ValueSubkeyRange {
|
|||||||
|
|
||||||
extension ValueSubkeyRangeExt on ValueSubkeyRange {
|
extension ValueSubkeyRangeExt on ValueSubkeyRange {
|
||||||
bool contains(int v) => low <= v && v <= high;
|
bool contains(int v) => low <= v && v <= high;
|
||||||
|
List<ValueSubkeyRange> remove(int v) {
|
||||||
|
if (v < low || v > high) {
|
||||||
|
return [this];
|
||||||
|
}
|
||||||
|
if (v == low) {
|
||||||
|
if (v == high) {
|
||||||
|
return [];
|
||||||
|
} else {
|
||||||
|
return [ValueSubkeyRange(low: v + 1, high: high)];
|
||||||
|
}
|
||||||
|
} else if (v == high) {
|
||||||
|
return [ValueSubkeyRange(low: low, high: v - 1)];
|
||||||
|
} else {
|
||||||
|
return [
|
||||||
|
ValueSubkeyRange(low: low, high: v - 1),
|
||||||
|
ValueSubkeyRange(low: v + 1, high: high)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ListValueSubkeyRangeExt on List<ValueSubkeyRange> {
|
extension ListValueSubkeyRangeExt on List<ValueSubkeyRange> {
|
||||||
bool containsSubkey(int v) => indexWhere((e) => e.contains(v)) != -1;
|
bool containsSubkey(int v) => indexWhere((e) => e.contains(v)) != -1;
|
||||||
|
List<ValueSubkeyRange> remove(int v) {
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
if (this[i].contains(v)) {
|
||||||
|
return [...sublist(0, i), ...this[i].remove(v), ...sublist(i + 1)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user