@ -23,8 +23,8 @@ private:
vector<Entry*> buckets;
public:
ArrayHashMap() {
// 初始化一个长度为 100 的桶(数组)
buckets= vector<Entry*>(100);
// 初始化数组,包含 100 个桶
buckets = vector<Entry*>(100);
}
/* 哈希函数 */
@ -26,7 +26,7 @@ class ArrayHashMap
private List<Entry?> buckets;
public ArrayHashMap()
{
buckets = new();
for (int i = 0; i < 100; i++)
@ -19,7 +19,7 @@ type arrayHashMap struct {
/* 初始化哈希表 */
func newArrayHashMap() *arrayHashMap {
buckets := make([]*entry, 100)
return &arrayHashMap{buckets: buckets}
@ -22,7 +22,7 @@ class Entry {
class ArrayHashMap {
private List<Entry> buckets;
public ArrayHashMap() {
buckets = new ArrayList<>();
for (int i = 0; i < 100; i++) {
buckets.add(null);
@ -16,7 +16,7 @@ class Entry {
#buckets;
constructor() {
this.#buckets = new Array(100).fill(null);
@ -18,7 +18,7 @@ class ArrayHashMap:
""" 基于数组简易实现的哈希表 """
def __init__(self):
""" 构造方法 """
# 初始化一个长度为 100 的桶(数组)
# 初始化数组,包含 100 个桶
self.buckets: List[Optional[Entry]] = [None] * 100
def hash_func(self, key: int) -> int:
@ -16,7 +16,7 @@ pub struct ArrayHashMap { buckets: Vec<Option<Entry>> }
impl ArrayHashMap {
pub fn new() -> ArrayHashMap {
Self { buckets: vec![None; 100] }
@ -20,7 +20,7 @@ class ArrayHashMap {
private var buckets: [Entry?] = []
init() {
for _ in 0 ..< 100 {
buckets.append(nil)
@ -21,7 +21,7 @@ class ArrayHashMap {
private readonly buckets: (Entry | null)[];
this.buckets = (new Array(100)).fill(null);
@ -29,7 +29,7 @@ pub fn ArrayHashMap(comptime T: type) type {
// 构造方法
pub fn init(self: *Self, allocator: std.mem.Allocator) !void {
self.mem_allocator = allocator;
self.buckets = std.ArrayList(?T).init(self.mem_allocator);
var i: i32 = 0;
while (i < 100) : (i += 1) {