The constructor function initializes a HashMap object with an optional initial collection and options.
The entryOrRawElements
parameter is an iterable collection of elements of a type
T
. It is an optional parameter and its default value is an empty array []
.
Optional
options: HashMapOptions<K, V, R>The options
parameter is an optional object that can contain two properties:
The function returns the size of an object.
The size of the object, which is a number.
The function returns the store object, which is a dictionary of HashMapStoreItem objects.
The store property is being returned. It is a dictionary-like object with string keys and values of type HashMapStoreItem<K, V>.
Protected
_getProtected
_getThe function _getNoObjKey
takes a key and returns a string representation of the key, handling
different types of keys.
The key
parameter is of type K
, which represents the type of the key being
passed to the _getNoObjKey
function.
a string value.
Protected
_isTime Complexity: O(n) Space Complexity: O(1)
The function is an implementation of the Symbol.iterator method that returns an iterable iterator.
Rest
...args: any[]The args
parameter in the code snippet represents a rest parameter. It
allows the function to accept any number of arguments as an array. In this case, the args
parameter is used to pass any additional arguments to the _getIterator
method.
Time Complexity: O(n) Space Complexity: O(n)
The clone function creates a new HashMap with the same key-value pairs as this one. The clone function is useful for creating a copy of an existing HashMap, and then modifying that copy without affecting the original.
A new hashmap with the same values as this one
The delete
function removes an element from a map-like data structure based on the provided key.
The key
parameter is the key of the element that you want to delete from the
data structure.
The delete
method returns a boolean value. It returns true
if the key was
successfully deleted from the map, and false
if the key was not found in the map.
Time Complexity: O(n) Space Complexity: O(1)
The every
function checks if every element in a collection satisfies a given condition.
The predicate
parameter is a callback function that takes three arguments:
value
, key
, and index
. It should return a boolean value indicating whether the condition is
met for the current element in the iteration.
Optional
thisArg: anyThe thisArg
parameter is an optional argument that specifies the value
to be used as this
when executing the predicate
function. If thisArg
is provided, it will be
passed as the first argument to the predicate
function. If thisArg
is not provided
The every
method is returning a boolean value. It returns true
if every element in
the collection satisfies the provided predicate function, and false
otherwise.
Time Complexity: O(n) Space Complexity: O(n)
The filter
function creates a new HashMap containing key-value pairs from the original HashMap
that satisfy a given predicate function.
The predicate parameter is a function that takes four arguments: value, key, index, and map. It is used to determine whether an element should be included in the filtered map or not. The function should return a boolean value - true if the element should be included, and false otherwise.
Optional
thisArg: anyThe thisArg
parameter is an optional argument that specifies the value
to be used as this
when executing the predicate
function. If thisArg
is provided, it will be
passed as the this
value to the predicate
function. If thisArg
is
The filter
method is returning a new HashMap
object that contains the key-value pairs
from the original HashMap
that pass the provided predicate
function.
Time Complexity: O(n) Space Complexity: O(1)
The find
function iterates over the entries of a collection and returns the first value for
which the callback function returns true.
The callback function that will be called for each entry in the collection. It takes three arguments: the value of the entry, the key of the entry, and the index of the entry in the collection. It should return a boolean value indicating whether the current entry matches the desired condition.
Optional
thisArg: anyThe thisArg
parameter is an optional argument that specifies the value
to be used as this
when executing the callbackfn
function. If thisArg
is provided, it will
be passed as the this
value to the callbackfn
function. If thisArg @returns The method
findreturns the value of the first element in the iterable that satisfies the provided callback function. If no element satisfies the callback function,
undefined` is
returned.
Time Complexity: O(n) Space Complexity: O(1)
The forEach
function iterates over each key-value pair in a collection and executes a callback
function for each pair.
The callback function that will be called for each element in the collection. It takes four parameters: the value of the current element, the key of the current element, the index of the current element, and the collection itself.
Optional
thisArg: anyThe thisArg
parameter is an optional argument that allows you to
specify the value of this
within the callback function. If thisArg
is provided, it will be
used as the this
value when calling the callback function. If thisArg
is not provided, `
The get
function retrieves a value from a map based on a given key, either from an object map or
a string map.
The key
parameter is the key used to retrieve a value from the map. It can be
of any type, but it should be compatible with the key type used when the map was created.
The method get(key: K)
returns a value of type V
if the key exists in the _objMap
or _store
, otherwise it returns undefined
.
The has
function checks if a given key exists in the _objMap
or _store
based on whether it
is an object key or not.
The parameter "key" is of type K, which means it can be any type.
The has
method is returning a boolean value.
Time Complexity: O(n) Space Complexity: O(1)
The function checks if a given value exists in a collection.
The parameter "value" is the value that we want to check if it exists in the collection.
a boolean value, either true or false.
Time Complexity: O(n) Space Complexity: O(n)
The map
function in TypeScript creates a new HashMap by applying a callback function to each
key-value pair in the original HashMap.
The callback function that will be called for each key-value pair in the HashMap. It takes four parameters:
Optional
thisArg: anyThe thisArg
parameter is an optional argument that specifies the value
to be used as this
when executing the callbackfn
function. If thisArg
is provided, it will
be passed as the this
value to the callbackfn
function. If thisArg @returns The
mapmethod is returning a new
HashMap` object with the transformed values based on
the provided callback function.
Time Complexity: O(n) Space Complexity: O(1)
The reduce
function iterates over key-value pairs and applies a callback function to each pair,
accumulating a single value.
The callback function that will be called for each element in the collection. It takes four arguments: the current accumulator value, the current value of the element, the key of the element, and the index of the element in the collection. It should return the updated accumulator value.
The initialValue
parameter is the initial value of the accumulator. It
is the value that will be used as the first argument to the callbackfn
function when reducing
the elements of the collection.
The reduce
method is returning the final value of the accumulator after iterating over
all the elements in the collection.
The set
function adds a key-value pair to a map-like data structure, incrementing the size if
the key is not already present.
The key parameter is the key used to identify the value in the data structure. It can be of any type, but if it is an object, it will be stored in a Map, otherwise it will be stored in a regular JavaScript object.
The value parameter represents the value that you want to associate with the key in the data structure.
Time Complexity: O(n) Space Complexity: O(1)
The "some" function iterates over a collection and returns true if at least one element satisfies a given predicate.
The predicate
parameter is a callback function that takes three arguments:
value
, key
, and index
. It should return a boolean value indicating whether the condition is
met for the current element in the iteration.
Optional
thisArg: anyThe thisArg
parameter is an optional argument that specifies the value
to be used as the this
value when executing the predicate
function. If thisArg
is provided,
it will be passed as the first argument to the predicate
function. If thisArg
is
a boolean value. It returns true if the predicate function returns true for any pair in the collection, and false otherwise.