xtd 0.2.0
Loading...
Searching...
No Matches
hash_code.h
Go to the documentation of this file.
1
4#pragma once
6#include "object.h"
7
9namespace xtd {
26 class hash_code : public xtd::object {
27 public:
29
32 hash_code() = default;
34
36
42 template<typename 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
48 bool equals(const xtd::object& other) const noexcept override;
49
50 xtd::size get_hash_code() const noexcept override;
51
55 xtd::size to_hash_code() const noexcept;
57
59
64 template<typename ...args_t>
65 static xtd::size combine(args_t... values) noexcept {return combine_iterator(generate_uniqueness_seed(), values...);}
67
68 private:
69 template<typename type_t, typename ...args_t>
70 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...);}
71 static xtd::size combine_iterator(xtd::size seed) noexcept;
72 static xtd::size hash_combine(xtd::size seed, xtd::size value) noexcept;
73 static xtd::size generate_uniqueness_seed() noexcept;
74
75 xtd::size hash_code_ = generate_uniqueness_seed();
76 };
77}
Combines the hash code for multiple values into a single hash code.
Definition hash_code.h: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.h:65
hash_code & add(const type_t value) noexcept
Adds a single value to the hash code.
Definition hash_code.h:43
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
size_t size
Represents a size of any object in bytes.
Definition size.h: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.h:10
Contains xtd::object class.
Implements a function object for hashing data.
Definition hasher.h:38