Added HashMap definition.

This commit is contained in:
Rafał Wrzeszcz
2014-07-25 14:24:05 +02:00
parent bd21e85b3b
commit 1f96102ae3
3 changed files with 96 additions and 0 deletions

View File

@@ -113,6 +113,7 @@ All definitions files include a header with the author and editors, so at some p
* [Google Url Shortener](https://developers.google.com/url-shortener/) (by [Frank M](https://github.com/sgtfrankieboy))
* [Hammer.js](http://eightmedia.github.com/hammer.js/) (by [Boris Yankov](https://github.com/borisyankov))
* [Handlebars](http://handlebarsjs.com/) (by [Boris Yankov](https://github.com/borisyankov))
* [HashMap](https://github.com/flesler/hashmap) (by [Rafał Wrzeszcz](https://wrzasq.pl))
* [HashSet](http://www.timdown.co.uk/jshashtable/jshashset.html) (by [Sergey Gerasimov](https://github.com/gerich-home))
* [Hashtable](http://www.timdown.co.uk/jshashtable/) (by [Sergey Gerasimov](https://github.com/gerich-home))
* [HelloJS](http://adodson.com/hello.js) (by [Pavel Zika](https://github.com/PavelPZ))

24
hashmap/hashmap-tests.ts Normal file
View File

@@ -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();

71
hashmap/hashmap.d.ts vendored Normal file
View File

@@ -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;
}