forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DefinitelyTyped#2561 from rafalwrzeszcz/feature/ha…
…shmap Added HashMap definition.
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/// <reference path="hashmap.d.ts"/> | ||
|
||
var map : HashMap<string, number> = new HashMap<string, number>(); | ||
|
||
map.set("foo", 123); | ||
|
||
var value : number = map.get("foo"); | ||
|
||
map.has("foo"); | ||
|
||
map.remove("foo"); | ||
|
||
var keys : string[] = map.keys(); | ||
|
||
var values : number[] = map.values(); | ||
|
||
var count : number = map.count(); | ||
|
||
map.forEach(function(value : number, key : string) : void { | ||
console.log(key); | ||
console.log(value); | ||
}); | ||
|
||
map.clear(); |
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,71 @@ | ||
// Type definitions for HashMap 1.1.0 | ||
// Project: https://github.com/flesler/hashmap | ||
// Definitions by: Rafał Wrzeszcz <http://wrzasq.pl> | ||
// Definitions: https://github.com/borisyankov/DefinitelyTyped | ||
|
||
declare class HashMap<KeyType, ValueType> { | ||
/** | ||
* Return value from hashmap. | ||
* | ||
* @param key Key. | ||
* @return Value stored under given key. | ||
*/ | ||
get(key : KeyType) : ValueType; | ||
|
||
/** | ||
* Store value in hashmap. | ||
* | ||
* @param key Key. | ||
* @param value Value. | ||
*/ | ||
set(key : KeyType, value : ValueType) : void; | ||
|
||
/** | ||
* Checks if given key exists in hashmap. | ||
* | ||
* @param key Key. | ||
* @return Whether given key exists in hashmap. | ||
*/ | ||
has(key : KeyType) : boolean; | ||
|
||
/** | ||
* Removes given key from hashmap. | ||
* | ||
* @param key Key. | ||
*/ | ||
remove(key : KeyType) : void; | ||
|
||
/** | ||
* Returns all contained keys. | ||
* | ||
* @return List of keys. | ||
*/ | ||
keys() : KeyType[]; | ||
|
||
/** | ||
* Returns all container values. | ||
* | ||
* @return List of values. | ||
*/ | ||
values() : ValueType[]; | ||
|
||
/** | ||
* Returns size of hashmap (number of entries). | ||
* | ||
* @return Number of entries in hashmap. | ||
*/ | ||
count() : number; | ||
|
||
/** | ||
* Clears hashmap. | ||
*/ | ||
clear() : void; | ||
|
||
/** | ||
* Iterates over hashmap. | ||
* | ||
* @param callback Function to be invoked for every hashmap entry. | ||
*/ | ||
forEach(callback : (value : ValueType, key : KeyType) => void) : void; | ||
} | ||
|