mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
castle: simplify find_next_top
Tops are no longer sparse in CastleProto, so the linear scan for holes isn't necessary.
This commit is contained in:
parent
15c2980948
commit
b87590ce9d
@ -721,10 +721,8 @@ const CharReach &CastleProto::reach() const {
|
|||||||
|
|
||||||
static
|
static
|
||||||
u32 find_next_top(const map<u32, PureRepeat> &repeats) {
|
u32 find_next_top(const map<u32, PureRepeat> &repeats) {
|
||||||
u32 top = 0;
|
u32 top = verify_u32(repeats.size());
|
||||||
for (; contains(repeats, top); top++) {
|
assert(!contains(repeats, top));
|
||||||
// pass
|
|
||||||
}
|
|
||||||
return top;
|
return top;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -734,7 +732,7 @@ u32 CastleProto::add(const PureRepeat &pr) {
|
|||||||
assert(pr.reports.size() == 1);
|
assert(pr.reports.size() == 1);
|
||||||
u32 top = find_next_top(repeats);
|
u32 top = find_next_top(repeats);
|
||||||
DEBUG_PRINTF("selected unused top %u\n", top);
|
DEBUG_PRINTF("selected unused top %u\n", top);
|
||||||
repeats.insert(make_pair(top, pr));
|
repeats.emplace(top, pr);
|
||||||
return top;
|
return top;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -783,7 +781,7 @@ bool mergeCastle(CastleProto &c1, const CastleProto &c2,
|
|||||||
const PureRepeat &pr = m.second;
|
const PureRepeat &pr = m.second;
|
||||||
DEBUG_PRINTF("top %u\n", top);
|
DEBUG_PRINTF("top %u\n", top);
|
||||||
u32 new_top = find_next_top(c1.repeats);
|
u32 new_top = find_next_top(c1.repeats);
|
||||||
c1.repeats.insert(make_pair(new_top, pr));
|
c1.repeats.emplace(new_top, pr);
|
||||||
top_map[top] = new_top;
|
top_map[top] = new_top;
|
||||||
DEBUG_PRINTF("adding repeat: map %u->%u\n", top, new_top);
|
DEBUG_PRINTF("adding repeat: map %u->%u\n", top, new_top);
|
||||||
}
|
}
|
||||||
@ -800,7 +798,7 @@ void remapCastleTops(CastleProto &proto, map<u32, u32> &top_map) {
|
|||||||
const u32 top = m.first;
|
const u32 top = m.first;
|
||||||
const PureRepeat &pr = m.second;
|
const PureRepeat &pr = m.second;
|
||||||
u32 new_top = find_next_top(out);
|
u32 new_top = find_next_top(out);
|
||||||
out.insert(make_pair(new_top, pr));
|
out.emplace(new_top, pr);
|
||||||
top_map[top] = new_top;
|
top_map[top] = new_top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user