哈希表(hash)

· · 算法·理论

哈希表

一、哈希表

哈希的应用主要分成两类:一类是哈希表,用于查找;另一类是字符串哈希,用于匹配

二、容器vector

函数名 操作功能 调用方式
begin() 获取vector中首元素的地址,即g[0]的地址 g.begin()
end() 获取vector中尾元素的下一地址(空) g.end()
size() 调用size()函数可以获得vector中保存的元素个数 g.size()
push_back(x) 在vector的最后面添加一个元素x g.push_back(x)
pop_back() 删除vector的末尾元素 g.pop_back()
clear() 用于清空vector中所有的元素 g.clear()
inline void insert(int x)
{
    h[has(x)].push_back(x);
}
inline bool find(int x)
{
    for(int i = 0; i < h[has(x)].size(); i++){
        if(h[has(x)][i] == x)return true;
    }
    return false;
}

三、map

想要调用 $map$ 则必须引用头文件`<map>` - 如下: ```cpp #include <map> ``` - 或**万能头**: ```cpp #include <bits/stdc++.h> ``` - 底层: $map$ 是使用[ `红黑树` ](https://baike.baidu.com/item/%E7%BA%A2%E9%BB%91%E6%A0%91/2413209?fr=ge_ala)来实现的, 因此 $map$ 中的元素默认按照键的 **升序** 进行排序。