This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to path utilities from pxth package (#101)
* Migrated to new pxth utilities * Created PxthMap abstraction * Fixed tests * Used getPxthSegments in tests * Removed 'values' function
- Loading branch information
1 parent
e515234
commit 9504df2
Showing
19 changed files
with
156 additions
and
424 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Pxth } from 'pxth'; | ||
|
||
import { hashPxth } from '../utils/hashPxth'; | ||
|
||
export class PxthMap<Value> { | ||
private _values: Record<string, Value> = {}; | ||
private _keys: Record<string, Pxth<unknown>> = {}; | ||
|
||
public get = <V>(key: Pxth<V>): Value => { | ||
return this._values[hashPxth(key)]; | ||
}; | ||
|
||
public set = <V>(key: Pxth<V>, value: Value) => { | ||
const stingifiedKey = hashPxth(key); | ||
this._values[stingifiedKey] = value; | ||
this._keys[stingifiedKey] = key as Pxth<unknown>; | ||
}; | ||
|
||
public remove = <V>(key: Pxth<V>) => { | ||
const stingifiedKey = hashPxth(key); | ||
delete this._values[stingifiedKey]; | ||
delete this._keys[stingifiedKey]; | ||
}; | ||
|
||
public has = <V>(key: Pxth<V>) => { | ||
return hashPxth(key) in this._values; | ||
}; | ||
|
||
public keys = (): Pxth<unknown>[] => Object.values(this._keys); | ||
|
||
public entries = (): Array<[key: Pxth<unknown>, value: Value]> => | ||
Object.entries(this._keys).map(([key, value]) => [value, this._values[key]]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.