常用操作

    访问;插入;删除;

    # -- codeing = utf-8 --
    # @Time : 2/7/2021 10:21 AM
    # @Autor : Caesar
    # @File : hash.py
    # @ Software : PyCharm
    # Create HashTable By Array
    hashTable = [‘’]*4
    # Create HashTable by Dictionary
    _mapping = {}

    # Add element
    # Time complexity: O(1)
    _hashTable[1] = “hanmeimei”
    hashTable[2] = “leihua”
    hashTable[3] = “siyangyuan”
    mapping[1] = “hanmeimei”
    mapping[2] = “lihua”
    mapping[3] = **”siyangyuan”
    # Update element
    # Time complexity:O(1)
    hashTable[1] = ‘’
    mapping.pop(1)
    # delete mapping[1]
    _# Get value
    # Time complexity: O(1)
    _print(hashTable[3])
    print(mapping[3])

    # Check value
    # Time complexity : O(1)
    # hashTable No
    if 3 in mapping:
    print(“键3属于在哈希表”)

    _# length of hashTable
    # Time complexity : O(1)
    _len(mapping)

    # is Empty
    # Time complexity: O(1)
    # hashTable No
    if len(mapping) == 0:
    print(“哈希表为空”)