zoukankan      html  css  js  c++  java
  • 不可改变性imutable

    不可改变性是指一些对象在被创建之后不会因为某些方式改变,特别是针对任何可以改变哈希对象的哈希值的方式。

    两者相联系是因为哈希键值一定是不可改变的,所以它们对应的哈希键值也不改变。

    如果允许它们改变,那么它们在数据结构如哈希表中的存储位置也会改变,因此会与哈希的概念违背,效率会大打折扣。

     

    Hashing is the process of converting some large amount of data into a much smaller amount (typically a single integer) in a repeatable way so that it can be looked up in a table in constant-time (O(1)), which is important for high-performance algorithms and data structures.

    Immutability is the idea that an object will not change in some important way after it has been created, especially in any way that might change the hash value of that object.

    The two ideas are related because objects which are used as hash keys must typically be immutable so their hash value doesn't change.  If it was allowed to change then the location of that object in a data structure such as a hashtable would change and then the whole purpose of hashing for efficiency is defeated.

    To really grasp the idea you should try to implement your own hashtable in a language like C/C++, or read the Java implementation of the HashMap class.

  • 相关阅读:
    单点登陆的javascript类原创
    goole图标
    字符串string的相关应用
    今天心情好,发首我喜欢的歌天黑黑
    爱情幸福!
    linux虚拟实现
    页面显示的问题
    由我们MIS的老师,所引发的一点感想.
    有关PERL5和正则表达式
    本来没有什么好说的!
  • 原文地址:https://www.cnblogs.com/sea-stream/p/10573069.html
Copyright © 2011-2022 走看看