Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#2561 from rafalwrzeszcz/feature/ha…
Browse files Browse the repository at this point in the history
…shmap

Added HashMap definition.
  • Loading branch information
vvakame committed Jul 25, 2014
2 parents bd21e85 + 1f96102 commit c2b858f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
24 changes: 24 additions & 0 deletions hashmap/hashmap-tests.ts
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();
71 changes: 71 additions & 0 deletions hashmap/hashmap.d.ts
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;
}

0 comments on commit c2b858f

Please sign in to comment.