mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
* spelling: add Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: attributes Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: bridging Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: deserialization Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: initialize Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: invariants Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: lazily Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: occurred Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: offset Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: optimization Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: our Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: process Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: substitution Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: the operation Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: the Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
67 lines
2.0 KiB
C++
67 lines
2.0 KiB
C++
//===--- GraphNodeWorklist.h ------------------------------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_BASIC_GRAPHNODEWORKLIST_H
|
|
#define SWIFT_BASIC_GRAPHNODEWORKLIST_H
|
|
|
|
#include "swift/Basic/LLVM.h"
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
/// Worklist of pointer-like things that have an invalid default value. This not
|
|
/// only avoids duplicates in the worklist, but also avoids revisiting
|
|
/// already-popped nodes. This makes it suitable for DAG traversal. This can
|
|
/// also be used within hybrid worklist/recursive traversal by recording the
|
|
/// size of the worklist at each level of recursion.
|
|
///
|
|
/// The primary API has two methods: initialize() and pop(). Others are provided
|
|
/// for flexibility.
|
|
template <typename T, unsigned SmallSize>
|
|
struct GraphNodeWorklist {
|
|
llvm::SmallPtrSet<T, SmallSize> nodeVisited;
|
|
llvm::SmallVector<T, SmallSize> nodeVector;
|
|
|
|
GraphNodeWorklist() = default;
|
|
|
|
GraphNodeWorklist(const GraphNodeWorklist &) = delete;
|
|
|
|
void initialize(T t) {
|
|
clear();
|
|
insert(t);
|
|
}
|
|
|
|
template <typename R>
|
|
void initializeRange(R &&range) {
|
|
clear();
|
|
nodeVisited.insert(range.begin(), range.end());
|
|
nodeVector.append(range.begin(), range.end());
|
|
}
|
|
|
|
T pop() { return empty() ? T() : nodeVector.pop_back_val(); }
|
|
|
|
bool empty() const { return nodeVector.empty(); }
|
|
|
|
unsigned size() const { return nodeVector.size(); }
|
|
|
|
void clear() {
|
|
nodeVector.clear();
|
|
nodeVisited.clear();
|
|
}
|
|
|
|
void insert(T t) {
|
|
if (nodeVisited.insert(t).second)
|
|
nodeVector.push_back(t);
|
|
}
|
|
};
|
|
|
|
#endif // SWIFT_BASIC_GRAPHNODEWORKLIST_H
|