Author: code34
Author Website: https://github.com/code34/oo_hashmap.Altis

Requirements: No addons required

Version: 0.50

Short description: OO HASHMAP is a class (object oriented) that permits to replace arma array with an hashmap object.

Support the author:

100% of your donation goes directly to the author of this content!
Date: 2017-11-06 12:49


Comments: (0)
Rating:



 





Object Oriented Hashmap

by
Code34


Description:
OO HASHMAP is a class (object oriented) that permits to replace arma array with an hashmap object.


Features:
Implementing the java hashmap interface
http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html


Installation / Usage:
- put the "oo_hashmap.sqf" and the "oop.h" files in your mission directory
- put this code into your mission init.sqf
- call compilefinal preprocessFileLineNumbers "oo_hasmap.sqf";

See example mission in directory: init.sqf

Functions:
clear()
Removes all of the mappings from this map.

containsKey(key)
Returns true if this map contains a mapping for the specified key.

containsValue(value)
Returns true if this map maps one or more keys to the specified value.

entrySet()
Returns a Set view of the mappings contained in this map.

get(key)
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

isEmpty()
Returns true if this map contains no key-value mappings.

keySet()
Returns a Set view of the keys contained in this map.

put(key, value)
Associates the specified value with the specified key in this map.

remove(key)
Removes the mapping for the specified key from this map if present.

size()
Returns the number of key-value mappings in this map.

Examples:
call compilefinal preprocessFileLineNumbers "oo_hashmap.sqf";
private ["_map", "_size", "_i", "_key", "_value"];

_map = ["new", []] call OO_HASHMAP;

_return = "isEmpty" call _map;
diag_log format["isempty %1", _return];

["put", ["toto", [3,7]]] call _map;
["put", ["tata", "turlututu"]] call _map;
["put", ["jp", "test du hashmap"]] call _map;

_return = ["containsKey", "toto"] call _map;
diag_log format["contains key toto %1", _return];

_return = ["containsValue", ["bullshit"]] call _map;
diag_log format["contains value bullshit %1", _return];

_return = ["containsValue", [[3,7]]] call _map;
diag_log format["contains value [3,7] %1", _return];

_return = "entrySet" call _map;
diag_log format["entryset %1", _return];

_return = ["get", "toto"] call _map;
diag_log format["get toto %1", _return];

_return = "isEmpty" call _map;
diag_log format["isempty %1", _return];

_return = "keySet" call _map;
diag_log format["keySet %1", _return];

_return = "size" call _map;
diag_log format["Size %1", _return];

["put", ["toto", [8,8]]] call _map;
["put", ["toto", [4,1]]] call _map;

_return = "keySet" call _map;
diag_log format["check for toto doublon, keySet %1", _return];

_return = ["get", "toto"] call _map;
diag_log format["after toto setting, get toto %1", _return];

["remove", "tata"] call _map;
diag_log "remove tata";

_return = ["containsKey", "tata"] call _map;
diag_log format["contains key tata %1", _return];

_return = "keySet" call _map;
diag_log format["after tata remove, keySet %1", _return];

_return = "entrySet" call _map;
diag_log format["after tata remove, entryset %1", _return];

"clear" call _map;

_return = "size" call _map;
diag_log format["Size %1 after clear", _return];

_return = "IsEmpty" call _map;
diag_log format["isempty %1", _return];


License:
You can share, modify, distribute this script but don't remove the licence and the name of the original author


Changelog:
0.50
- fix private keywords

0.40
- improve perfomance with native array

v0.3
- use key string now
- use missionnamespace instead entryset array
- remove useless code
- fix test init code & add some use cases
- fix function names typo
- remove slow searchindex function

v0.2
- add documentation
- add performance improvements
- fix clear function

v0.1
- first release


Forum topic:
- BI forums




Enable javascript to be able to download from Armaholic please!



Tags: Script,   Function,   Object Oriented,   Hashmap,   Array,   Oo