基于上一章的内容,我们需要把key替换成hash值存储到b+tree中
首先要改变的就是set和get函数
template<typename T>
int smallsql::getType()
{
return typeid(T) == typeid(int) ? 0 : 1;
}
template<typename T>
void smallsql::set(const std::string& key, const T& value)
{
unsigned long iKey = HashString(key, 1);
int type = getType<T>();
SqlData<T>* pItem = static_cast<SqlData<T>*>(bplus_tree_get(m_pTree, iKey, type));
if (pItem == nullptr)
{
bplus_tree_put(m_pTree, iKey, nullptr, type);
pItem = new SqlData<T>();
pItem->value = value;
bplus_tree_put(m_pTree, iKey, pItem, type);
}
else
{
pItem->value = value;
}
}
template<typename T>
T smallsql::get(const std::string& key)
{
unsigned long iKey = HashString(key, 1);
int type = getType<T>();
SqlData<T>* pItem = static_cast<SqlData<T>*>(bplus_tree_get(m_