Skip to content

fix: make AttributeReference's SetType be a std::set #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions libs/common/include/attribute_reference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <algorithm>
#include <cstddef>
#include <ostream>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>

#include <boost/container_hash/hash.hpp>
Expand Down Expand Up @@ -33,18 +33,7 @@ namespace launchdarkly {
*/
class AttributeReference {
public:
/**
* Provides a hashing function for use with unordered sets.
*/
struct HashFunction {
std::size_t operator()(AttributeReference const& ref) const {
return boost::hash_range(ref.components_.begin(),
ref.components_.end());
}
};

using SetType = std::unordered_set<AttributeReference,
AttributeReference::HashFunction>;
using SetType = std::set<AttributeReference>;

/**
* Get the component of the attribute reference at the specified depth.
Expand All @@ -56,36 +45,36 @@ class AttributeReference {
* @return The component at the specified depth or an empty string if the
* depth is out of bounds.
*/
std::string const& component(std::size_t depth) const;
[[nodiscard]] std::string const& component(std::size_t depth) const;

/**
* Get the total depth of the reference.
*
* For example, depth() on the reference `/a/b/c` would return 3.
* @return
*/
std::size_t depth() const;
[[nodiscard]] std::size_t depth() const;

/**
* Check if the reference is a "kind" reference. Either `/kind` or `kind`.
*
* @return True if it is a kind reference.
*/
bool is_kind() const;
[[nodiscard]] bool is_kind() const;

/** Check if the reference is valid.
*
* @return True if the reference is valid.
*/
bool valid() const;
[[nodiscard]] bool valid() const;

/**
* The redaction name will always be an attribute reference compatible
* string. So, for instance, a literal that contained `/attr` would be
* converted to `/~1attr`.
* @return String to use in redacted attributes.
*/
std::string const& redaction_name() const;
[[nodiscard]] std::string const& redaction_name() const;

/**
* Create an attribute from a string that is known to be an attribute
Expand Down