Skip to content

Conversation

@SolidWallOfCode
Copy link
Member

@SolidWallOfCode SolidWallOfCode commented Oct 24, 2018

This updates the API for hash functions in ATS to make it suitable for external (plugin) use.
The basic hashes are moved to the extern C++ area. The more obscure hashes are kept in core, and MD5 isn't exported because that would create a dependency on the openSSL library.

Also, I need this for the YAML work.
Depends on #4480.

Caller is responsible for freeing ring node memory.
*/

struct ATSConsistentHash {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as you're in here, why is this a struct not a class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd have to ask @jrushford - I wanted to minimize the changes in this area, it's really outside the scope of the PR.

virtual self_type &update(std::string_view const &data) = 0;

/// Finalize the hash function output.
virtual self_type & final() = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Although final is a keyword, it's not a reserve word. Consistency is the hobgoblin of little programming languages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change that, it's a legacy from pre-eleventy days.

};

/// A hash function that returns a 32 bit result.
struct Hash32Functor : HashFunctor {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I looked it up structures, unlike classes, have public inheritance by default. Or, you could say public and people would not have to look it up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interview question - you shouldn't have to look it up. It's less obscure than "final" being a keyword.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha too late already hired me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like struct for that exact reason, it instantly tells me that it's all public, and I don't think we should discourage the use of struct over class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zwoop I was referring to using default access control for inheritance. I prefer it explicit, unlike SolidWallOfObscurity.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made another comment above, questioning the use of struct instead of class, when the class has some members with private or protected access control.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this particular case, it's inertia. When I write new code, I tend to follow Leif's approach and only use struct for POD things.

* The main purpose of this is to allow run time changes in hashing, which is required in various
* circumstances.
*/
struct HashFunctor {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't functors supposed to have a function call operator?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to suggestions for a better name. I thought "Hash" was too generic. OTOH the point of this is to embed a function, which makes it a functor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashBase? HashSuper? HashSmoker?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"HashFunction", except you'd complain it wasn't a function. "HashFunctionContainer" :-). "HashWrap".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashAbstract

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashFunctorish
HashFunctoresque
HashFunkyFunctor
HashFlunktor

virtual size_t size() const = 0;

/// Copy the result to @a dst.
/// @a dst must be at least @c result_size bytes long.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artifact from some API reshuffling.


/// Copy the result to @a dst.
/// @a dst must be at least @c result_size bytes long.
/// @return @c true if the result was copied to @a data, @c false otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/data/dst/
?

@SolidWallOfCode
Copy link
Member Author

I shuffled the API around quite a bit working on this, I need to review the comments and make sure they're consistent with the final API.


template <typename X, typename V> self_type &update(TransformView<X, V> view);

template <typename X, typename V> value_type hash_immediate(TransformView<X, V> const &view);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this take a reference rather than a value param like update()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because update uses the parameter as local variable and hash_immediate doesn't. It shouldn't matter from a caller's point of view.


/// Check if view is empty.
bool empty() const;
/// Check if bool is not empty.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/bool/view/
?

@SolidWallOfCode SolidWallOfCode force-pushed the hash-function-refresh branch 2 times, most recently from 98bd959 to b318330 Compare October 31, 2018 20:14
This updates the API for hash functions in ATS to make it suitable for external (plugin) use.
The basic hashes are moved to the extern C++ area.
@zwoop zwoop removed this from the 9.0.0 milestone Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants