summaryrefslogtreecommitdiffstats
path: root/contrib/libs/antlr4_cpp_runtime/src/support/BitSet.h
diff options
context:
space:
mode:
authorvitalyisaev <[email protected]>2023-11-30 13:26:22 +0300
committervitalyisaev <[email protected]>2023-11-30 15:44:45 +0300
commit0a98fece5a9b54f16afeb3a94b3eb3105e9c3962 (patch)
tree291d72dbd7e9865399f668c84d11ed86fb190bbf /contrib/libs/antlr4_cpp_runtime/src/support/BitSet.h
parentcb2c8d75065e5b3c47094067cb4aa407d4813298 (diff)
YQ Connector:Use docker-compose in integrational tests
Diffstat (limited to 'contrib/libs/antlr4_cpp_runtime/src/support/BitSet.h')
-rw-r--r--contrib/libs/antlr4_cpp_runtime/src/support/BitSet.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/contrib/libs/antlr4_cpp_runtime/src/support/BitSet.h b/contrib/libs/antlr4_cpp_runtime/src/support/BitSet.h
new file mode 100644
index 00000000000..bb30364be08
--- /dev/null
+++ b/contrib/libs/antlr4_cpp_runtime/src/support/BitSet.h
@@ -0,0 +1,76 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "antlr4-common.h"
+
+namespace antlrcpp {
+
+ class ANTLR4CPP_PUBLIC BitSet : public std::bitset<2048> {
+ public:
+ size_t nextSetBit(size_t pos) const {
+ for (size_t i = pos; i < size(); i++){
+ if (test(i)) {
+ return i;
+ }
+ }
+
+ return INVALID_INDEX;
+ }
+
+ // Prints a list of every index for which the bitset contains a bit in true.
+ friend std::wostream& operator << (std::wostream& os, const BitSet& obj)
+ {
+ os << "{";
+ size_t total = obj.count();
+ for (size_t i = 0; i < obj.size(); i++){
+ if (obj.test(i)){
+ os << i;
+ --total;
+ if (total > 1){
+ os << ", ";
+ }
+ }
+ }
+
+ os << "}";
+ return os;
+ }
+
+ static std::string subStringRepresentation(const std::vector<BitSet>::iterator &begin,
+ const std::vector<BitSet>::iterator &end) {
+ std::string result;
+ std::vector<BitSet>::iterator vectorIterator;
+
+ for (vectorIterator = begin; vectorIterator != end; vectorIterator++) {
+ result += vectorIterator->toString();
+ }
+ // Grab the end
+ result += end->toString();
+
+ return result;
+ }
+
+ std::string toString() const {
+ std::stringstream stream;
+ stream << "{";
+ bool valueAdded = false;
+ for (size_t i = 0; i < size(); ++i){
+ if (test(i)){
+ if (valueAdded) {
+ stream << ", ";
+ }
+ stream << i;
+ valueAdded = true;
+ }
+ }
+
+ stream << "}";
+ return stream.str();
+ }
+
+ };
+}