Skip to content

Commit 7774f06

Browse files
committed
Change IndexTrie to allow signed indices
1 parent 85ff15a commit 7774f06

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

include/swift/Basic/IndexTrie.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@ namespace swift {
2222

2323
// Trie node representing a sequence of unsigned integer indices.
2424
class IndexTrieNode {
25-
static const unsigned RootIdx = ~0U;
26-
unsigned Index;
25+
public:
26+
static const int RootIndex = std::numeric_limits<int>::min();
27+
28+
private:
29+
int Index;
2730
llvm::SmallVector<IndexTrieNode*, 8> Children;
2831
IndexTrieNode *Parent;
2932

3033
public:
31-
IndexTrieNode(): Index(RootIdx), Parent(nullptr) {}
34+
IndexTrieNode() : Index(RootIndex), Parent(nullptr) {}
3235

33-
explicit IndexTrieNode(unsigned V, IndexTrieNode *P): Index(V), Parent(P) {}
36+
explicit IndexTrieNode(int V, IndexTrieNode *P) : Index(V), Parent(P) {}
3437

3538
IndexTrieNode(IndexTrieNode &) =delete;
3639
IndexTrieNode &operator=(const IndexTrieNode&) =delete;
@@ -40,19 +43,18 @@ class IndexTrieNode {
4043
delete N;
4144
}
4245

43-
bool isRoot() const { return Index == RootIdx; }
46+
bool isRoot() const { return Index == RootIndex; }
4447

4548
bool isLeaf() const { return Children.empty(); }
4649

47-
unsigned getIndex() const { return Index; }
50+
int getIndex() const { return Index; }
4851

49-
IndexTrieNode *getChild(unsigned Idx) {
50-
assert(Idx != RootIdx);
52+
IndexTrieNode *getChild(int Idx) {
53+
assert(Idx != RootIndex);
5154

52-
auto I = std::lower_bound(Children.begin(), Children.end(), Idx,
53-
[](IndexTrieNode *a, unsigned i) {
54-
return a->Index < i;
55-
});
55+
auto I =
56+
std::lower_bound(Children.begin(), Children.end(), Idx,
57+
[](IndexTrieNode *a, int i) { return a->Index < i; });
5658
if (I != Children.end() && (*I)->Index == Idx)
5759
return *I;
5860
auto *N = new IndexTrieNode(Idx, this);

0 commit comments

Comments
 (0)