backup a easy implement

# coding: utf-8

def add(k, v):
pass def get(target):
pass class LinearMap(object):
"""线性表结构"""
def __init__(self):
self.items = [] def add(self, k, v):
self.items.append((k, v)) def get(self, k):
for key, val in self.items:
if key == k:
return val
raise KeyError class BetterMap(object):
"""利用 LinearMap 对象作为子表,建立更快的查询表"""
def __init__(self, n=100):
self.maps = [] # 总表格
for i in range(n):
self.maps.append(LinearMap()) def find_map(self, k):
index = hash(k) % len(self.maps)
return self.maps[index] def add(self, k, v):
m = self.find_map(k)
m.add(k, v) def get(self, k):
m = self.find_map(k)
return m.get(k) class HashMap(object):
def __init__(self):
self.maps = BetterMap(2)
self.num = 0 def get(self, k):
return self.maps.get(k) def add(self,k, v):
if self.num == len(self.maps.maps):
self.resize()
self.maps.add(k, v)
self.num += 1 def resize(self):
new_maps = BetterMap(self.num * 2)
for m in self.maps.maps:
for k, v in m.items:
new_maps.add(k, v) self.maps = new_maps

Reference:

https://www.cnblogs.com/hanahimi/p/4765265.html  hash 表学习笔记

http://python.jobbole.com/86522/?utm_source=blog.jobbole.com&utm_medium=relatedPosts  Python源码分析-PyDictObject

https://www.nosuchfield.com/2016/07/29/the-python-implementationp-of-HashTable/  HashTable 的 Python 实现

https://harveyqing.gitbooks.io/python-read-and-write/content/python_advance/python_dict_implementation.html  Python字典实现

【纪录】Hash about的更多相关文章

  1. 11-散列4 Hashing - Hard Version (30 分)

    Given a hash table of size N, we can define a hash function H(x)=x%N. Suppose that the linear probin ...

  2. sql 查询强制使用HASH连接性能测试比较

    HASH JOIN 散列连接 hash join是CBO 做大数据集连接时的常用方式.优化器扫描小表(或数据源),利用连接键(也就是根据连接字段计算hash 值)在内存中建立hash表,然后扫描大表, ...

  3. Sql优化(一) Merge Join vs. Hash Join vs. Nested Loop

    原创文章,首发自本人个人博客站点,转载请务必注明出自http://www.jasongj.com Nested Loop,Hash Join,Merge Join介绍 Nested Loop: 对于被 ...

  4. Hash查找法在Keil C51中的实现

    摘要:散列(hash)是一种重要的存储方法,也是一种常见的查找方法.它是指在记录的存储位置和它的关键字之间建立一个确定的对应关系.本文以射频卡门禁控制器为例,说明用射频卡卡号作为关键字,用Hash查找 ...

  5. stl源码分析之hash table

    本文主要分析g++ stl中哈希表的实现方法.stl中,除了以红黑树为底层存储结构的map和set,还有用哈希表实现的hash_map和hash_set.map和set的查询时间是对数级的,而hash ...

  6. html5之hash

    http://blog.csdn.net/u012028371/article/details/67636395 原文:https://www.studyscript.com/Post/index/i ...

  7. MySQL(12)---纪录一次left join一对多关系而引起的BUG

    MySQL(11)---纪录一次left join一对多关系而引起的bug BUG背景 我们有一个订单表 和 一个 物流表 它们通过 订单ID 进行一对一的关系绑定.但是由于物流表在保存订单信息的时候 ...

  8. 纪录一次left join一对多关系而引起的BUG

    纪录一次left join一对多关系而引起的BUG MySQL(11)---纪录一次left join一对多关系而引起的bug BUG背景 我们有一个订单表 和 一个 物流表 它们通过 订单ID 进行 ...

  9. 在 aws emr 上,将 hbase table A 的数据,对 key 做 hash,写到另外一张 table B

    先 scan 原表,然后 bulkload 到新表. 采坑纪录1. bulkload 产生 hfile 前,需要先对 hash(key) 做 repartition,在 shuffle 的 read ...

随机推荐

  1. C#从IE缓存读取图片

    如果用HttpWebRequest和HttpWebResponse从服务器取图片,会触发图片变化.于是想到从IE缓存读取图片 参考https://www.cnblogs.com/yelaiju/arc ...

  2. UVA12563-Jin Ge Jin Qu hao(动态规划基础)

    Problem UVA12563-Jin Ge Jin Qu hao Accept: 642  Submit: 7638Time Limit: 3000 mSec Problem Descriptio ...

  3. maven 配置文件settings.xml设置

    打开这个配置文件 在相应标签下配置这些内容 //将中央仓库修改为阿里云的仓库 <mirrors> <mirror> <id>nexus-aliyun</id& ...

  4. robotframework的字符类型转换,用Evaluate来转换

    ${b} BuiltIn.Set Variable 1.1 ${c}= BuiltIn.Evaluate float(${b}) ${d}= BuiltIn.Evaluate ${c}+2.2 1.有 ...

  5. Centos7 安装配置mysql5.6

    Centos7下完美安装并配置mysql5.6   Centos7将默认数据库mysql替换成了Mariadb,对于我们这些还想用mysql的人来说并不是一个好消息. 最近我搜罗了网上各种安装教程,各 ...

  6. idea 2018.1 for mac JRebel破解

    第一步: 在 Idea 中下载 Jrebel 路径:preferences-plugins-Browse repositories-直接搜索下载 Jrebel   第二步:配置反向代理工具 1.安装 ...

  7. Generative Adversarial Nets[CycleGAN]

    本文来自<Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks>,时间线为2017 ...

  8. glance系列一:glance基础

    一 什么是glance glance即image service,是为虚拟机的创建提供镜像的服务 二 为何要有glance 我们基于openstack是构建基本的Iaas平台对外提供虚拟机,而虚拟机在 ...

  9. ORACLE存储过程中%TYPE和%ROWTYPE的区别

    ORACLE存储过程中%TYPE和%ROWTYPE的区别 在存储过程中%TYPE和%ROWTYPE常用来在PL/SQL中定义变量 因为 t_emp emp%rowtype ;这个语句的意思是 定义一个 ...

  10. npm install 安装报错:npm ERR! EPERM npm ERR! -4048 npm ERR! Error: EPERM: operation not permitted, unlink 'D:\test\demo\code\materialT\node_modules\.staging'

    更新项目依赖包,删除掉package-lock.json.node_modules,运行npm install,报如上错误信息,查询资料说是没有权限,本人用管理员身份打开powershell,运行np ...