xtd 0.2.0
hash_code.hpp
Go to the documentation of this file.
1
4#pragma once
6#include "object.hpp"
7
9namespace xtd {
26 class hash_code : public xtd::object {
27 public:
29
32 hash_code() = default;
34
36
42 template<class type_t>
43 hash_code& add(const type_t value) noexcept {
44 hash_code_ = hash_combine(hash_code_, xtd::collections::generic::helpers::hasher<type_t> {}(value));
45 return *this;
46 }
47
51 bool equals(const xtd::object& other) const noexcept override;
52
55 xtd::size get_hash_code() const noexcept override;
56
60 xtd::size to_hash_code() const noexcept;
62
64
69 template<class ...args_t>
70 static xtd::size combine(args_t... values) noexcept {return combine_iterator(generate_uniqueness_seed(), values...);}
72
73 private:
74 template<class type_t, class ...args_t>
75 static xtd::size combine_iterator(xtd::size seed, type_t value, args_t... values) noexcept {return combine_iterator(hash_combine(seed, xtd::collections::generic::helpers::hasher<type_t> {}(value)), values...);}
76 static xtd::size combine_iterator(xtd::size seed) noexcept;
77 static xtd::size hash_combine(xtd::size seed, xtd::size value) noexcept;
78 static xtd::size generate_uniqueness_seed() noexcept;
79
80 xtd::size hash_code_ = generate_uniqueness_seed();
81 };
82}
Combines the hash code for multiple values into a single hash code.
Definition hash_code.hpp:26
xtd::size get_hash_code() const noexcept override
Serves as a hash function for a particular type.
xtd::size to_hash_code() const noexcept
Calculates the final hash code after consecutive xtd::hash_code::add invocations.
hash_code()=default
Create a new instance of the class hash_code.
bool equals(const xtd::object &other) const noexcept override
Determines whether the specified object is equal to the current object.
static xtd::size combine(args_t... values) noexcept
Combines values into a hash code.
Definition hash_code.hpp:70
hash_code & add(const type_t value) noexcept
Adds a single value to the hash code.
Definition hash_code.hpp:43
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
@ other
The operating system is other.
Contains xtd::collections::generic::helpers::hasher struct.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::object class.
Implements a function object for hashing data.
Definition hasher.hpp:39