mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 06:07:20 +08:00 
			
		
		
		
	Update hash_map docs
This commit is contained in:
		@ -512,9 +512,8 @@ $$
 | 
				
			|||||||
    ```typescript title="array_hash_map.ts"
 | 
					    ```typescript title="array_hash_map.ts"
 | 
				
			||||||
    /* 键值对 Number -> String */
 | 
					    /* 键值对 Number -> String */
 | 
				
			||||||
    class Entry {
 | 
					    class Entry {
 | 
				
			||||||
 | 
					    public key: number;
 | 
				
			||||||
        public key: number;
 | 
					    public val: string;
 | 
				
			||||||
        public val: string;
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        constructor(key: number, val: string) {
 | 
					        constructor(key: number, val: string) {
 | 
				
			||||||
            this.key = key;
 | 
					            this.key = key;
 | 
				
			||||||
@ -525,7 +524,7 @@ $$
 | 
				
			|||||||
    /* 基于数组简易实现的哈希表 */
 | 
					    /* 基于数组简易实现的哈希表 */
 | 
				
			||||||
    class ArrayHashMap {
 | 
					    class ArrayHashMap {
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        private readonly bucket: Entry | null[];
 | 
					        private readonly bucket: (Entry | null)[];
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        constructor() {
 | 
					        constructor() {
 | 
				
			||||||
            // 初始化一个长度为 100 的桶(数组)
 | 
					            // 初始化一个长度为 100 的桶(数组)
 | 
				
			||||||
@ -559,8 +558,8 @@ $$
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        /* 获取所有键值对 */
 | 
					        /* 获取所有键值对 */
 | 
				
			||||||
        public entries(): Entry[] {
 | 
					        public entries(): (Entry | null)[] {
 | 
				
			||||||
            let arr = [];
 | 
					            let arr: (Entry | null)[] = [];
 | 
				
			||||||
            for (let i = 0; i < this.bucket.length; i++) {
 | 
					            for (let i = 0; i < this.bucket.length; i++) {
 | 
				
			||||||
                if (this.bucket[i]) {
 | 
					                if (this.bucket[i]) {
 | 
				
			||||||
                    arr.push(this.bucket[i]);
 | 
					                    arr.push(this.bucket[i]);
 | 
				
			||||||
@ -570,22 +569,22 @@ $$
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        /* 获取所有键 */
 | 
					        /* 获取所有键 */
 | 
				
			||||||
        public keys(): number[] {
 | 
					        public keys(): (number | undefined)[] {
 | 
				
			||||||
            let arr = [];
 | 
					            let arr: (number | undefined)[] = [];
 | 
				
			||||||
            for (let i = 0; i < this.bucket.length; i++) {
 | 
					            for (let i = 0; i < this.bucket.length; i++) {
 | 
				
			||||||
                if (this.bucket[i]) {
 | 
					                if (this.bucket[i]) {
 | 
				
			||||||
                    arr.push(this.bucket[i].key);
 | 
					                    arr.push(this.bucket[i]?.key);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return arr;
 | 
					            return arr;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        /* 获取所有值 */
 | 
					        /* 获取所有值 */
 | 
				
			||||||
        public values(): string[] {
 | 
					        public values(): (string | undefined)[] {
 | 
				
			||||||
            let arr = [];
 | 
					            let arr: (string | undefined)[] = [];
 | 
				
			||||||
            for (let i = 0; i < this.bucket.length; i++) {
 | 
					            for (let i = 0; i < this.bucket.length; i++) {
 | 
				
			||||||
                if (this.bucket[i]) {
 | 
					                if (this.bucket[i]) {
 | 
				
			||||||
                    arr.push(this.bucket[i].val);
 | 
					                    arr.push(this.bucket[i]?.val);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return arr;
 | 
					            return arr;
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user