`
blueyanghualong
  • 浏览: 225349 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

HashObject之LinkedHashObjectMap(2)

 
阅读更多
private abstract class LinkedBaseHashObjectIterator implements Iterator<T> {
LinkedBaseHashObject nextObject    = header.after;
LinkedBaseHashObject lastReturned = null;

/**
* The modCount value that the iterator believes that the backing
* List should have.  If this expectation is violated, the iterator
* has detected concurrent modification.
*/
int expectedModCount = modCount;

public boolean hasNext() {
            return nextObject != header;
}

public void remove() {
    if (lastReturned == null)
     throw new IllegalStateException();
    if (modCount != expectedModCount)
     throw new ConcurrentModificationException();

    LinkedHashObjectMap.this.remove(lastReturned);
        lastReturned = null;
        expectedModCount = modCount;
}

T nextObject() {
    if (modCount != expectedModCount)
       throw new ConcurrentModificationException();
        if (nextObject == header)
                throw new NoSuchElementException();

        LinkedBaseHashObject e = lastReturned = nextObject;
        nextObject = e.after;
        return (T)e;
}
}

private class ObjectIterator extends LinkedBaseHashObjectIterator {
public T next() { return (T)nextObject(); }
}

    // These Overrides alter the behavior of superclass view iterator() methods
Iterator<T> newObjectIterator() { return new ObjectIterator(); }

/**
* 复写了父类的addObject方法,
* 支持双向链表功能,新添加的数据,会放在链表顶部。
* 支持老化数据的功能。
*/
void addObject(int hash, BaseHashObject object, int bucketIndex) {
LinkedBaseHashObject old = (LinkedBaseHashObject)table[bucketIndex];
LinkedBaseHashObject e = (LinkedBaseHashObject)object;
e.next = old;
    table[bucketIndex] = e;
    e.addBefore(header);
    size++;
        // Remove eldest entry if instructed, else grow capacity if appropriate
        LinkedBaseHashObject eldest = header.after;
        if (removeEldestEntry(eldest)) {
            removeObjectForKey(eldest);
        } else {
            if (size >= threshold)
                resize(2 * table.length);
        }
    }
    /**
     * 判断是否要老化数据
     * @param eldest
     * @return
     */
protected boolean removeEldestEntry(LinkedBaseHashObject eldest) {
if(log.isDebugEnabled())
{
log.debug("size():"+size()+";maxUserCount:"+maxUserCount);
}
if(size()> maxUserCount)
            return true;
return false;
    }

public int getMaxUserCount() {
return maxUserCount;
}
    /**
     * 设值缓存最大值
     * @param maxUserCount
     */
public void setMaxUserCount(int maxUserCount) {
this.maxUserCount = maxUserCount;
if(log.isDebugEnabled())
{
log.debug("set maxUserCount:"+maxUserCount);
}
}

}

分享到:
评论

相关推荐

    SAS Hash Object Programming

    Hash programming in SAS. to show you how hash objects in SAS DATA steps can be used to lookup ...you should be able to start wisely incorporating hash object programming techniques in your applications.

    hash-obj:获取对象的哈希

    import hashObject from 'hash-obj' ; hashObject ( { ':unicorn:' : ':rainbow:' } , { algorithm : 'sha1' } ) ; //=&gt; '3de3bc784035b559784fc276f47493d60555fba3' 原料药 hashObject(对象,选项?) 目的 类型...

    ObjectHash.zip

    "ObjectHash.zip"文件中的内容很可能是一个C#代码示例,演示了如何对对象进行哈希处理。 首先,C#标准库提供了多种哈希类,如`System.Security.Cryptography`命名空间下的`SHA256`、`MD5`、`CRC32`等,它们都可用于...

    Excel的MD5加密的2种实现方式

    HashBytes = HashObject.ComputeHash_2(StrConv(PlainText, vbFromUnicode)) MD5Hash = Join(Left$(Hex$(b), 2) For Each b In HashBytes) End Function ``` 这段代码定义了一个名为`MD5Hash`的VBA函数,接受一个...

    Hash算法之SHA1实现c++

    SHA1(Secure Hash Algorithm 1)是一种广泛使用的散列函数,属于哈希算法的一种,它能够将任意长度的输入(也叫做预映射)通过一个单向函数转换为固定长度的输出,通常这个长度是160位。SHA1算法在网络安全、数据...

    git-hash-object:就像从git hash-object一样计算对象ID

    就像从git hash-object一样计算对象ID。 安装 npm install git-hash-object 用法 const gitHashObject = require ( "git-hash-object" ) ; gitHashObject ( "Hello World" ) ; //=&gt; "5e1c309dae7f45e0f39b1bf3ac3...

    HASH算法之MD5算法

    hash函数之md5程序,可运行,包含testbench

    Python库 | murmurhash2-0.2.0-cp37-none-win_amd64.whl

    **Python库 murmurhash2-0.2.0-cp37-none-win_amd64.whl** 在Python编程环境中,库是实现特定功能的模块集合,它们极大地扩展了Python的功能,使得开发者能够轻松处理各种任务。`murmurhash2-0.2.0-cp37-none-win_...

    k2hash_nodejs:K2HASH nodejs插件库-NoSQL键值存储(KVS)nodejs库

    k2hash nodejs插件库 用于Node.js的K2HASH插件库。 K2HASH-Yahoo!的NoSQL键值存储(KVS)库日本 总览 K2HASH是NoSQL(键值存储)库和Yahoo!的库工具。 日本。 该插件库用于在nodejs上使用K2HASH。 通过k2hash ...

    hashids:一个用于 http 的 Clojure 包装库

    安装 [hashobject/hashids "0.2.0"]用法 user=&gt; (use 'hashids.core)niluser=&gt; (encrypt 134 "super-secret-salt")"Lzn"user=&gt; (decrypt "Lzn" "super-secret-salt")134user=&gt; (encrypt 225 "super-secret-salt")"7...

    uthash hash string

    Any C structure can be stored in a hash table using uthash. Just add a UT_hash_handle to the structure and choose one or more fields in your structure to act as the key. Then use these macros to store...

    uthash User Guide

    2. **结构体定义**:在定义结构体时,需要包含`#include "uthash.h"`头文件,并在结构体末尾添加`UT_hash_handle hh;`声明,这样就为结构体添加了哈希功能。 3. **插入操作**:使用`HASH_ADD`宏将新元素插入到哈希...

    Hash值检测工具

    1. **MD5(Message-Digest Algorithm 5)**: 是最早的广泛使用的Hash函数之一,产生一个128位(16字节)的Hash值,通常以32个十六进制字符表示。尽管MD5已经被发现存在安全性问题,即存在碰撞(两个不同的文件可能...

    Hash-Hash-Hash

    Hash-Hash-Hash

    Hash基础知识_Hash基础知识_

    Hash基础知识_Hash基础知识_Hash基础知识_Hash基础知识_Hash基础知识_Hash基础知识_

    Hash算法 MD2, MD5, SHA-1, SHA-256, SHA-384, or SHA-512

    实现多种Hash算法,包括MD2, MD5, SHA-1, SHA-256, SHA-384, SHA-512

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

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

    Hash值校验工具

    2. 更新Hash值数据库:对于已知的恶意文件Hash值,应及时更新数据库,以保持最新的防护能力。 3. 防止中间人攻击:在进行文件传输时,如果网络被中间人攻击,攻击者可能篡改文件并同时更改提供的Hash值,所以应直接...

    辅助工具Hash.zip

    辅助工具Hash.zip

Global site tag (gtag.js) - Google Analytics