Update a comment in array_hash_map

pull/420/head
krahets 2 years ago
parent d5afd93571
commit 518b9efabc

@ -23,8 +23,8 @@ private:
vector<Entry*> buckets; vector<Entry*> buckets;
public: public:
ArrayHashMap() { ArrayHashMap() {
// 初始化一个长度为 100 的桶(数组) // 初始化数组,包含 100 个桶
buckets= vector<Entry*>(100); buckets = vector<Entry*>(100);
} }
/* 哈希函数 */ /* 哈希函数 */

@ -26,7 +26,7 @@ class ArrayHashMap
private List<Entry?> buckets; private List<Entry?> buckets;
public ArrayHashMap() public ArrayHashMap()
{ {
// 初始化一个长度为 100 的桶(数组) // 初始化数组,包含 100 个桶
buckets = new(); buckets = new();
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {

@ -19,7 +19,7 @@ type arrayHashMap struct {
/* 初始化哈希表 */ /* 初始化哈希表 */
func newArrayHashMap() *arrayHashMap { func newArrayHashMap() *arrayHashMap {
// 初始化一个长度为 100 的桶(数组) // 初始化数组,包含 100 个桶
buckets := make([]*entry, 100) buckets := make([]*entry, 100)
return &arrayHashMap{buckets: buckets} return &arrayHashMap{buckets: buckets}
} }

@ -22,7 +22,7 @@ class Entry {
class ArrayHashMap { class ArrayHashMap {
private List<Entry> buckets; private List<Entry> buckets;
public ArrayHashMap() { public ArrayHashMap() {
// 初始化一个长度为 100 的桶(数组) // 初始化数组,包含 100 个桶
buckets = new ArrayList<>(); buckets = new ArrayList<>();
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
buckets.add(null); buckets.add(null);

@ -16,7 +16,7 @@ class Entry {
class ArrayHashMap { class ArrayHashMap {
#buckets; #buckets;
constructor() { constructor() {
// 初始化一个长度为 100 的桶(数组) // 初始化数组,包含 100 个桶
this.#buckets = new Array(100).fill(null); this.#buckets = new Array(100).fill(null);
} }

@ -18,7 +18,7 @@ class ArrayHashMap:
""" 基于数组简易实现的哈希表 """ """ 基于数组简易实现的哈希表 """
def __init__(self): def __init__(self):
""" 构造方法 """ """ 构造方法 """
# 初始化一个长度为 100 的桶(数组) # 初始化数组,包含 100 个桶
self.buckets: List[Optional[Entry]] = [None] * 100 self.buckets: List[Optional[Entry]] = [None] * 100
def hash_func(self, key: int) -> int: def hash_func(self, key: int) -> int:

@ -16,7 +16,7 @@ pub struct ArrayHashMap { buckets: Vec<Option<Entry>> }
impl ArrayHashMap { impl ArrayHashMap {
pub fn new() -> ArrayHashMap { pub fn new() -> ArrayHashMap {
// 初始化一个长度为 100 的桶(数组) // 初始化数组,包含 100 个桶
Self { buckets: vec![None; 100] } Self { buckets: vec![None; 100] }
} }

@ -20,7 +20,7 @@ class ArrayHashMap {
private var buckets: [Entry?] = [] private var buckets: [Entry?] = []
init() { init() {
// 100 // 100
for _ in 0 ..< 100 { for _ in 0 ..< 100 {
buckets.append(nil) buckets.append(nil)
} }

@ -21,7 +21,7 @@ class ArrayHashMap {
private readonly buckets: (Entry | null)[]; private readonly buckets: (Entry | null)[];
constructor() { constructor() {
// 初始化一个长度为 100 的桶(数组) // 初始化数组,包含 100 个桶
this.buckets = (new Array(100)).fill(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 { pub fn init(self: *Self, allocator: std.mem.Allocator) !void {
self.mem_allocator = allocator; self.mem_allocator = allocator;
// 100 // 100
self.buckets = std.ArrayList(?T).init(self.mem_allocator); self.buckets = std.ArrayList(?T).init(self.mem_allocator);
var i: i32 = 0; var i: i32 = 0;
while (i < 100) : (i += 1) { while (i < 100) : (i += 1) {

Loading…
Cancel
Save