1#ifndef SOURCEMETA_CORE_JSON_PROPERTY_SET_H_
2#define SOURCEMETA_CORE_JSON_PROPERTY_SET_H_
4#ifndef SOURCEMETA_CORE_JSON_EXPORT
5#include <sourcemeta/core/json_export.h>
8#include <sourcemeta/core/json_hash.h>
9#include <sourcemeta/core/json_value.h>
16namespace sourcemeta::core {
23#pragma warning(disable : 4251 4275)
45class SOURCEMETA_CORE_JSON_EXPORT JSONPropertySet {
47 JSONPropertySet() =
default;
52 using hash_type = JSON::Object::hash_type;
54 using value_type = std::pair<string_type, hash_type>;
56 using underlying_type = std::vector<value_type>;
57 using size_type = underlying_type::size_type;
58 using difference_type = underlying_type::difference_type;
59 using const_iterator = underlying_type::const_iterator;
64 const hash_type hash)
const ->
bool {
65 assert(HASHER(value) == hash);
66 if (HASHER.is_perfect(hash)) {
70 for (
const auto &entry : this->data_) {
71 if (entry.second == hash && entry.first.size() == value.size()) {
76 for (
const auto &entry : this->data_) {
77 if (entry.second == hash && entry.first == value) {
88 return this->
contains(value, HASHER(value));
112 [[nodiscard]]
auto at(
const size_type index)
const noexcept
113 ->
const value_type & {
114 assert(index < this->data_.size());
115 return this->data_[index];
119 [[nodiscard]]
auto empty() const noexcept ->
bool {
120 return this->data_.empty();
124 [[nodiscard]]
auto size() const noexcept -> size_type {
125 return this->data_.size();
129 [[nodiscard]]
auto begin() const noexcept -> const_iterator {
130 return this->data_.begin();
134 [[nodiscard]]
auto end() const noexcept -> const_iterator {
135 return this->data_.end();
139 [[nodiscard]]
auto cbegin() const noexcept -> const_iterator {
140 return this->data_.cbegin();
144 [[nodiscard]]
auto cend() const noexcept -> const_iterator {
145 return this->data_.cend();
157 underlying_type data_;
auto size() const noexcept -> size_type
Get the number of property names in the set.
Definition json_property_set.h:124
auto empty() const noexcept -> bool
Check whether the set is empty.
Definition json_property_set.h:119
std::basic_string< Char, CharTraits, Allocator< Char > > String
The string type used by the JSON document.
Definition json_value.h:52
static auto from_json(const JSON &value) -> std::optional< JSONPropertySet >
auto insert(string_type &&value) -> bool
auto contains(const string_type &value) const -> bool
Check whether the set contains a property name.
Definition json_property_set.h:87
auto contains(const string_type &value, const hash_type hash) const -> bool
Definition json_property_set.h:63
auto insert(const string_type &value, const hash_type hash) -> bool
auto to_json() const -> JSON
Serialise the set as a JSON array of property names.
auto insert(const string_type &value) -> bool
auto insert(string_type &&value, const hash_type hash) -> bool
auto at(const size_type index) const noexcept -> const value_type &
Get a property name and its hash by index.
Definition json_property_set.h:112
JSON::String string_type
The type of the property names held by the set.
Definition json_property_set.h:50