`

hash/index/atom

阅读更多
1. Hash.c/hash.h

typedef struct hash
{
    HashFunctions fun;   /* Function block */
    int is_allocated;    /* 0 iff hash structure is on stack or is static */
    ErtsAlcType_t type;
    char* name;          /* Table name (static string, for debugging) */
    int size; /* Number of slots */
    int size20percent;   /* 20 percent of number of slots */
    int size80percent;   /* 80 percent of number of slots */
    int ix;              /* Size index in size table */
    int used; /* Number of slots used */
    HashBucket** bucket; /* Vector of bucket pointers (objects) */
} Hash;

函数:
typedef struct hash_functions
{
    H_FUN hash; //取值
    HCMP_FUN cmp; //比较
    HALLOC_FUN alloc;
    HFREE_FUN free;
} HashFunctions;

桶:
/*
** This bucket must be placed in top of
** every object that uses hashing!!!
** (Object*) == (Object*) &bucket
*/
typedef struct hash_bucket
{
    struct hash_bucket* next; /* Next bucket */
    HashValue hvalue;           /* Store hash value for get, rehash */
} HashBucket;

查找:
/*
** Find an object in the hash table
**
*/
void* hash_get(Hash* h, void* tmpl)
{
    HashValue hval = h->fun.hash(tmpl);
    int ix = hval % h->size;
    HashBucket* b = h->bucket[ix];

    while(b != (HashBucket*) 0) {
if ((b->hvalue == hval) && (h->fun.cmp(tmpl, (void*)b) == 0))
    return (void*) b;
b = b->next;
    }
    return (void*) 0;
}

Rehash???
2. Index.c/index.h


typedef struct index_table
{
    Hash htable; /* Mapping obj -> index */
    ErtsAlcType_t type;
    int size; /* Allocated size */
    int limit; /* Max size */
    int entries; /* Number of entries */
    IndexSlot*** seg_table; /* Mapping index -> obj */
} IndexTable;


Hash中应该存储的是 obj -> index(即IndexSlot*)


int
index_put(IndexTable* t, void* tmpl)
{
    int ix;
    IndexSlot* p = (IndexSlot*) hash_put(&t->htable, tmpl);

    if (p->index >= 0) {
return p->index;
    }

    ix = t->entries;
    if (ix >= t->size) {
Uint sz;
if (ix >= t->limit) {
    erl_exit(1, "no more index entries in %s (max=%d)\n",
     t->htable.name, t->limit);
}
sz = INDEX_PAGE_SIZE*sizeof(IndexSlot*);
t->seg_table[ix>>INDEX_PAGE_SHIFT] = erts_alloc(t->type, sz);
t->size += INDEX_PAGE_SIZE;
    }
    t->entries++;
    p->index = ix;
    t->seg_table[ix>>INDEX_PAGE_SHIFT][ix&INDEX_PAGE_MASK] = p;
    return ix;
}

其实就是hash表,再加一个Index -> HashBucket的映射(即IndexSlot*)

3. Atom
typedef struct atom {
    IndexSlot slot;  /* MUST BE LOCATED AT TOP OF STRUCT!!! */
    int len;         /* length of atom name */
    int ord0;        /* ordinal value of first 3 bytes + 7 bits */
    byte* name;      /* name of atom */
} Atom;

Eterm
am_atom_put(const char* name, int len)
{
    Atom a;
    Eterm ret;
    int aix;

    /*
     * Silently truncate the atom if it is too long. Overlong atoms
     * could occur in situations where we have no good way to return
     * an error, such as in the I/O system. (Unfortunately, many
     * drivers don't check for errors.)
     *
     * If an error should be produced for overlong atoms (such in
     * list_to_atom/1), the caller should check the length before
     * calling this function.
     */
    if (len > MAX_ATOM_LENGTH) {
len = MAX_ATOM_LENGTH;
    }
    a.len = len;
    a.name = (byte*)name;
    atom_read_lock();
    aix = index_get(&erts_atom_table, (void*) &a);
    atom_read_unlock();
    if (aix >= 0)
ret = make_atom(aix);
    else {
atom_write_lock();
ret = make_atom(index_put(&erts_atom_table, (void*) &a));
atom_write_unlock();
    }
    return ret;
}
如果erts_atom_table中有这个atom,则直接生成一个atom;
否则先index_put进来,在生成一个atom

#define make_atom(x)  ((Eterm)(((x) << _TAG_IMMED2_SIZE) + _TAG_IMMED2_ATOM))

Atom的Eterm就是把一个index包上tag,length。。。
分享到:
评论

相关推荐

    UrlHash/锚点

    使用《UrlHash/锚点》解决移动设备中的单页面应用的物理[返回键]带来的困扰 示例代码

    文件MD5/HASH/CRC32计算

    自动计算所选文件的MD5/HASH/CRC32,速度非常快。格式:MD5: C5DDF48C2A4052C214E764A2F3FCA570 SHA1: C6CAD627354F24F86BB980508900EB32F7D408D0 CRC32: C369D67E

    hashcat [hashcat wiki].rar

    hashcat is the world’s fastest and most advanced password recovery tool. This version combines the previous CPU-based hashcat (now called hashcat-legacy) and GPU-based oclHashcat. Hashcat is ...

    hashcat-5.1.0.rar

    This version combines the previous CPU-based hashcat (now called hashcat-legacy) and GPU-based oclHashcat. Hashcat is released as open source software under the MIT license. Current Version ...

    General Purpose Hash Function Algorithms Library

    (* URL: http://www.partow.net/programming/hashfunctions/index.html *) (* *) (* Copyright notice: *) (* Free use of the General Purpose Hash Function Algorithms Library is *) (* permitted under ...

    vue中重定向redirect:‘/index‘,不显示问题、跳转出错的完美解决

    Vue Router默认使用哈希模式(`hash: '#!'`),在这种模式下,`#`后面的路径不会触发服务器请求,而是由浏览器处理。如果后端重定向只包含了`http://my.app.com/`,而没有`#/login`,那么前端路由可能不会生效。...

    串口收发,多字符串发送、HID、TCP、DES/MAC、AES、SM4、HASH/MD5/CRC/XOR/异或和、累加和

    HASH(哈希)函数如MD5(Message-Digest Algorithm 5)和SHA系列,用于将任意长度的数据转换为固定长度的摘要,常用于数据校验和完整性检查。CRC(Cyclic Redundancy Check)是循环冗余校验,也是一种常用的错误检测...

    webqq hash算法c#版(20160218)

    webqq最新hash算法c#版,20160218完成,由webqq的js算法翻译而来。 计算结果完全一致,请放心使用。 /// /// QQ hash算法 /// &lt;/summary&gt; /// &lt;param name="b"&gt;QQ号&lt;/param&gt; /// &lt;param name="j"&gt;cookie的ptwebqq值...

    mysql_hash.exe/使用hash登陆mysql

    在获取到mysql用户的hash后, 可用hash直接登陆mysql进行操作 比如我们注入出数据库的hash,但是没办法拿到webshell 我们可以使用mysql_hash,用hash登陆并控制数据库 使用方法: mysql_hash.exe -u root -p Enter ...

    hashcat-5.1.0.zip

    hashcat使用CPU/GPU破译(系统密码、wifi,rar、MD5), Cracking WPA/WPA2 with oclHashcat:...在线cap转为hccap格式:https://hashcat.net/cap2hccap/ Git:https://github.com/hashcat/hashcat

    hash字符串函数总结

    在计算机科学中,哈希(Hash)函数是一种用于将任意长度的数据映射为固定长度输出的算法。这种输出通常称为哈希值,它在数据结构(如哈希表)、密码学、数字签名等领域有着广泛的应用。本文将对几种常见的字符串哈希...

    hashcat-utils-1.9.7z

    hashcat-utils Hashcat-utils are a set of small utilities that are useful in advanced password cracking Brief description They all are packed into multiple stand-alone binaries. All of these utils ...

    hashcat-4.1.0.7

    当前最强大的开源密码恢复工具,你可以访问Hashcat.net网站来了解这款工具的详细情况。本质上,Hashcat 3.0是一款高级密码恢复工具,可以利用CPU或GPU资源来攻击160多种哈希类型的密码

    JS-url插件

    // http://rob:abcd1234@www.example.com/path/index.html?query1=test&silly=willy#test=hash&chucky=cheese url('domain'); // example.com url('hostname'); // www.example.com url('tld'); // com url('sub');...

    高运算性能,低碰撞率的hash算法MurmurHash算法.zip

    MurmurHash算法由Austin Appleby创建于2008年,现已应用到Hadoop、libstdc 、nginx、libmemcached,Redis,Memcached,Cassandra,HBase,Lucene等开源系统。2011年Appleby被Google雇佣,随后Google推出其变种的...

    hashin失效vumat_hashin破坏准则_vumatfailure_vumathashin失效_hashin_vumat

    在IT行业中,尤其是在模拟仿真和材料科学领域,Hashin失效准则是一种广泛应用的理论,用于预测多相复合材料的破坏行为。VUMAT(User-Defined Viscoplasticity and Damage Material Subroutine)是ABAQUS软件中的一个...

    oracle分区表之hash分区表的使用及扩展

    Oracle分区表中的Hash分区是一种基于哈希算法的分区策略,适用于处理无法清晰定义分区范围的大型数据表。这种分区方式通过计算分区键的哈希值来决定数据存储在哪个分区,以此达到数据分散和负载均衡的目的。Hash分区...

    C/OC_geohash

    《C/OC_geohash:理解与应用》 在信息技术领域,地理编码是将地理位置转换为数字表示的重要过程,而Geohash就是一种高效的地理编码技术。Geohash基于坐标系统,采用分形空间划分的方法,将地球表面的任意位置转化...

    GEOHASH Javascript的实现

    1. `index.html`:网页主文件,用于展示`GEOHASH`的JavaScript实现。 2. `geohash-demo.js`:包含`GEOHASH`的JavaScript实现代码,可能包括编码、解码以及相邻`GEOHASH`的计算功能。 3. `labeledmarker.js`:可能是...

    Nginx安装url_hash插件.doc

    **Nginx与url_hash插件** Nginx是一个高性能的HTTP和反向代理服务器,以其轻量级、高并发处理能力以及丰富的模块扩展性而闻名。然而,Nginx本身并不内置支持url_hash功能,这是一个用于负载均衡的策略,通过将特定...

Global site tag (gtag.js) - Google Analytics