Sha256: abf14b0618678aa43351885bd330735c45238d48574c97161a088daad7ac443d

Contents?: true

Size: 1.79 KB

Versions: 19

Compression:

Stored size: 1.79 KB

Contents

/* 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();
    }

  };
}

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
expressir-1.4.2 ext/express_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.4.1 ext/express_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.4.0 ext/express_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.3.3 ext/express_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.3.2 ext/express_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.3.1 ext/express_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.3.0 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.3.0.pre.5 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.3.0.pre.2 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.3.0.pre.1 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.2.11 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.2.10 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.2.9 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
factorial-presto-parser-1.0.7 ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
did_parser-1.0.0 ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.2.8 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.2.7 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.2.6 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h
expressir-1.2.5 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h