Sha256: 01b02beb0e0c22fd71bfa6c7c1e13707cf6b057cebecd8ed0c4494dffc610df4

Contents?: true

Size: 1.63 KB

Versions: 19

Compression:

Stored size: 1.63 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.
 */

#include "misc/Interval.h"

using namespace antlr4::misc;

const Interval Interval::INVALID;

size_t Interval::hashCode() const {
  size_t hash = 23;
  hash = hash * 31 + static_cast<size_t>(a);
  hash = hash * 31 + static_cast<size_t>(b);
  return hash;
}

bool Interval::startsBeforeDisjoint(const Interval &other) const {
  return a < other.a && b < other.a;
}

bool Interval::startsBeforeNonDisjoint(const Interval &other) const {
  return a <= other.a && b >= other.a;
}

bool Interval::startsAfter(const Interval &other) const {
  return a > other.a;
}

bool Interval::startsAfterDisjoint(const Interval &other) const {
  return a > other.b;
}

bool Interval::startsAfterNonDisjoint(const Interval &other) const {
  return a > other.a && a <= other.b; // b >= other.b implied
}

bool Interval::disjoint(const Interval &other) const {
  return startsBeforeDisjoint(other) || startsAfterDisjoint(other);
}

bool Interval::adjacent(const Interval &other) const {
  return a == other.b + 1 || b == other.a - 1;
}

bool Interval::properlyContains(const Interval &other) const {
  return other.a >= a && other.b <= b;
}

Interval Interval::Union(const Interval &other) const {
  return Interval(std::min(a, other.a), std::max(b, other.b));
}

Interval Interval::intersection(const Interval &other) const {
  return Interval(std::max(a, other.a), std::min(b, other.b));
}

std::string Interval::toString() const {
  return std::to_string(a) + ".." + std::to_string(b);
}

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/misc/Interval.cpp
expressir-1.4.1 ext/express_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.4.0 ext/express_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.3.3 ext/express_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.3.2 ext/express_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.3.1 ext/express_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.3.0 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.3.0.pre.5 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.3.0.pre.2 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.3.0.pre.1 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.2.11 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.2.10 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.2.9 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
factorial-presto-parser-1.0.7 ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
did_parser-1.0.0 ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.2.8 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.2.7 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.2.6 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp
expressir-1.2.5 ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp