EHS/include/ehs/HashMap.h

146 lines
2.6 KiB
C
Raw Normal View History

2024-01-31 22:28:19 -08:00
/*
#pragma once
#include "EHS.h"
#include <type_traits>
namespace ehs
{
template<typename V>
class HashNode
{
private:
V value;
HashNode child;
public:
HashNode()
{
}
HashNode(const V value)
: value(value)
{
}
HashNode(const HashNode& node)
: value(node.value), child(node.child)
{
}
HashNode& operator==(const HashNode& node)
{
value = node.value;
child = node.child;
return *this;
}
void SetValue(const V value)
{
this->value = value;
}
V GetValue() const
{
return value;
}
void SetChild(const HashNode child)
{
this->child = child;
}
HashNode* GetChild()
{
return &child;
}
};
/// 1000
template<typename V, typename N = USize>
class HashMap
{
private:
HashNode<V>** data;
N size;
public:
~HashMap()
{
if (data)
{
delete[] data;
data = nullptr;
size = 0;
}
}
HashMap()
: data(nullptr), size(0)
{
}
HashMap(const N size)
: data(new HashNode<V>(size)), size(size)
{
}
HashMap(const HashMap& map)
: data(new HashNode<V>*(map.size)), size(map.size)
{
for (N i = 0; i < map.size; ++i)
data[i] = map.data[i];
}
HashMap& operator=(const HashMap& map)
{
if (this == &map)
return *this;
data = new HashNode<V>*(map.size);
size = map.size;
for (N i = 0; i < size; ++i)
data[i] = map.data[i];
return *this;
}
template<typename K>
void Insert(const K key, const V value)
{
}
template<>
void Insert(const Str_8& key, const V value)
{
N hash = 0;
for (N i = 0; i < key.Size(); ++i)
hash += key[i];
hash %= size;
if (data[hash])
{
HashNode<V> child = data[hash]->GetChild();
if (child)
}
else
{
data[hash] = new HashNode<V>(value);
}
}
private:
SetChildRecursive()
{
}
};
}
*/