Update ESLint configuration, package.json, and README; improve formatting and versioning consistency. Adjust TypeScript configuration to disallow importing extensions and refine test scripts for better readability.
This commit is contained in:
44
README.md
44
README.md
@@ -64,24 +64,24 @@ new HashMap<K, V>(
|
||||
|
||||
### Methods
|
||||
|
||||
| Method | Description | Time Complexity |
|
||||
|--------|-------------|-----------------|
|
||||
| `set(key: K, value: V): void` | Insert or update a key-value pair | O(1) average |
|
||||
| `get(key: K): V \| undefined` | Retrieve value by key | O(1) average |
|
||||
| `has(key: K): boolean` | Check if key exists | O(1) average |
|
||||
| `delete(key: K): boolean` | Remove entry by key | O(1) average |
|
||||
| `clear(): void` | Remove all entries | O(n) |
|
||||
| `keys(): IterableIterator<K>` | Iterator over keys | O(n) |
|
||||
| `values(): IterableIterator<V>` | Iterator over values | O(n) |
|
||||
| `entries(): IterableIterator<[K, V]>` | Iterator over entries | O(n) |
|
||||
| `forEach(callback): void` | Execute callback for each entry | O(n) |
|
||||
| Method | Description | Time Complexity |
|
||||
| ------------------------------------- | --------------------------------- | --------------- |
|
||||
| `set(key: K, value: V): void` | Insert or update a key-value pair | O(1) average |
|
||||
| `get(key: K): V \| undefined` | Retrieve value by key | O(1) average |
|
||||
| `has(key: K): boolean` | Check if key exists | O(1) average |
|
||||
| `delete(key: K): boolean` | Remove entry by key | O(1) average |
|
||||
| `clear(): void` | Remove all entries | O(n) |
|
||||
| `keys(): IterableIterator<K>` | Iterator over keys | O(n) |
|
||||
| `values(): IterableIterator<V>` | Iterator over values | O(n) |
|
||||
| `entries(): IterableIterator<[K, V]>` | Iterator over entries | O(n) |
|
||||
| `forEach(callback): void` | Execute callback for each entry | O(n) |
|
||||
|
||||
### Properties
|
||||
|
||||
| Property | Description |
|
||||
|----------|-------------|
|
||||
| `size` | Number of key-value pairs |
|
||||
| `capacity` | Current number of buckets |
|
||||
| Property | Description |
|
||||
| ------------ | ------------------------------------- |
|
||||
| `size` | Number of key-value pairs |
|
||||
| `capacity` | Current number of buckets |
|
||||
| `loadFactor` | Current load factor (size / capacity) |
|
||||
|
||||
## Advanced Usage
|
||||
@@ -108,7 +108,7 @@ class CaseInsensitiveHashFunction implements IHashFunction<string> {
|
||||
const map = new HashMap<string, number>(
|
||||
16,
|
||||
0.75,
|
||||
new CaseInsensitiveHashFunction()
|
||||
new CaseInsensitiveHashFunction(),
|
||||
);
|
||||
|
||||
map.set("Hello", 1);
|
||||
@@ -122,11 +122,7 @@ Use the built-in `NumericHashFunction` for better distribution with numeric keys
|
||||
```typescript
|
||||
import { HashMap, NumericHashFunction } from "@techniker-me/hash-map";
|
||||
|
||||
const map = new HashMap<number, string>(
|
||||
16,
|
||||
0.75,
|
||||
new NumericHashFunction()
|
||||
);
|
||||
const map = new HashMap<number, string>(16, 0.75, new NumericHashFunction());
|
||||
|
||||
map.set(12345, "value1");
|
||||
map.set(67890, "value2");
|
||||
@@ -155,25 +151,30 @@ console.log(user?.name); // "Alice"
|
||||
This implementation adheres to all five SOLID principles:
|
||||
|
||||
### 1. Single Responsibility Principle (SRP)
|
||||
|
||||
- `HashMap` - Manages hash map operations
|
||||
- `HashNode` - Stores key-value pairs
|
||||
- `DefaultHashFunction` - Handles hashing logic
|
||||
- Each class has one clear purpose
|
||||
|
||||
### 2. Open/Closed Principle (OCP)
|
||||
|
||||
- Extensible through custom hash functions
|
||||
- Core implementation is closed for modification
|
||||
|
||||
### 3. Liskov Substitution Principle (LSP)
|
||||
|
||||
- All implementations correctly implement their interfaces
|
||||
- Subtypes can replace their base types without breaking functionality
|
||||
|
||||
### 4. Interface Segregation Principle (ISP)
|
||||
|
||||
- `IHashMap` - Focused map operations
|
||||
- `IHashFunction` - Minimal hashing interface
|
||||
- Clients depend only on interfaces they use
|
||||
|
||||
### 5. Dependency Inversion Principle (DIP)
|
||||
|
||||
- Depends on `IHashFunction` abstraction, not concrete implementations
|
||||
- High-level modules don't depend on low-level modules
|
||||
|
||||
@@ -230,6 +231,7 @@ bun test --coverage
|
||||
```
|
||||
|
||||
**Test Coverage: 100%** ✅
|
||||
|
||||
- 66 comprehensive tests
|
||||
- 1,168 assertions
|
||||
- All edge cases covered
|
||||
|
||||
Reference in New Issue
Block a user