/**
 * @file Dictionary.js
 * @description 字典工具类 - 键值对存储
 */

/**
 * 字典类 - 提供类似Map的键值对存储功能
 */
export class Dictionary<T = unknown> {
    private items: Record<string, T> = {};

    /** 检查是否存在指定键 */
    Has(key: string): boolean {
        return key in this.items;
    }

    /** 设置键值对 */
    Set(key: string, value: T): void {
        this.items[key] = value;
    }

    /** 移除指定键 */
    Remove(key: string): boolean {
        if (this.Has(key)) {
            delete this.items[key];
            return true;
        }
        return false;
    }

    /** 获取指定键的值 */
    Get(key: string): T | undefined {
        return this.Has(key) ? this.items[key] : undefined;
    }

    /** 获取所有键 */
    Keys(): string[] {
        return Object.keys(this.items);
    }

    /** 获取所有值 */
    Values(): T[] {
        return Object.values(this.items);
    }

    /** 清空字典 */
    Clear(): void {
        this.items = {};
    }
}
