ListHashUtil
public final class ListHashUtil
io/agentscope/core/state/ListHashUtil.java:48–171列表 Hash Util,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.core.state 包。核心成员包括 computeHash、hasChanged、needsFullRewrite。
Utility class for computing hash values of state lists.
This class provides hash computation for change detection in AgentStateStore implementations. The hash is used to detect if a list has been modified (not just appended) since the last save operation.
The hash computation uses a sampling strategy to avoid iterating over large lists:
-
For small lists (≤5 elements): all elements are included
-
For large lists: samples at positions 0, 1/4, 1/2, 3/4, and last
Usage in AgentStateStore implementations:
`String currentHash = ListHashUtil.computeHash(values);
String storedHash = readStoredHash();
if (storedHash != null && !storedHash.equals(currentHash)) {
// List was modified, need full rewrite
rewriteEntireList(values);
} else if (values.size() > existingCount) {
// List grew, can append incrementally
appendNewItems(values);
}
`
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public static String computeHash(List<? extends State> values)static | 计算 `computeHash`。 Compute a hash value for a list of state objects. |
public static boolean hasChanged(String currentHash, String storedHash)static | 判断是否具有 `hasChanged`。 Check if the list has changed based on hash comparison. |
public static boolean needsFullRewrite(List<? extends State> currentValues, String storedHash, int existingCount)static | 执行 `needsFullRewrite` 方法。 Determine if a full rewrite is needed based on list content and existing count. |
方法详情Method Detail
computeHash
public static String computeHash(List<? extends State> values)
计算 computeHash。
Compute a hash value for a list of state objects.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
values | List<? extends State> | 值(类型 `List`)。the list of state objects to hash |
Stringio/agentscope/core/state/ListHashUtil.java:76–95hasChanged
public static boolean hasChanged(String currentHash, String storedHash)
判断是否具有 hasChanged。
Check if the list has changed based on hash comparison.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
currentHash | String | 当前 Hash(类型 `String`)。the hash of the current list |
storedHash | String | 已存储 Hash(类型 `String`)。the previously stored hash (may be null) |
booleanio/agentscope/core/state/ListHashUtil.java:131–137needsFullRewrite
public static boolean needsFullRewrite(List<? extends State> currentValues, String storedHash, int existingCount)
执行 needsFullRewrite 方法。
Determine if a full rewrite is needed based on list content and existing count.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
currentValues | List<? extends State> | 当前值(类型 `List`)。the current complete list of state objects |
storedHash | String | 已存储 Hash(类型 `String`)。the previously stored hash (may be null) |
existingCount | int | existing 数量(类型 `int`)。the count of items already stored |
booleanio/agentscope/core/state/ListHashUtil.java:147–170