5#include "flutter/shell/platform/windows/sequential_id_generator.h"
13void Remove(uint32_t
key,
T* first,
T* second) {
14 auto iter = first->find(
key);
15 if (iter == first->end())
18 uint32_t second_key = iter->second;
21 iter = second->find(second_key);
28 : min_id_(min_id), min_available_id_(min_id), max_id_(max_id) {}
33 auto it = number_to_id_.find(number);
34 if (it != number_to_id_.end())
37 auto id = GetNextAvailableId();
38 number_to_id_.emplace(number,
id);
39 id_to_number_.emplace(
id, number);
44 return number_to_id_.find(number) != number_to_id_.end();
48 if (number_to_id_.count(number) > 0
U) {
49 UpdateNextAvailableIdAfterRelease(number_to_id_[number]);
50 Remove(number, &number_to_id_, &id_to_number_);
55 if (id_to_number_.count(
id) > 0
U) {
56 UpdateNextAvailableIdAfterRelease(
id);
57 Remove(id_to_number_[
id], &number_to_id_, &id_to_number_);
61uint32_t SequentialIdGenerator::GetNextAvailableId() {
62 while (id_to_number_.count(min_available_id_) > 0 &&
63 min_available_id_ < max_id_) {
66 if (min_available_id_ >= max_id_)
67 min_available_id_ = min_id_;
68 return min_available_id_;
71void SequentialIdGenerator::UpdateNextAvailableIdAfterRelease(uint32_t
id) {
72 if (
id < min_available_id_) {
73 min_available_id_ =
id;
bool HasGeneratedIdFor(uint32_t number) const
void ReleaseId(uint32_t id)
SequentialIdGenerator(uint32_t min_id, uint32_t max_id)
void ReleaseNumber(uint32_t number)
uint32_t GetGeneratedId(uint32_t number)