The constructor initializes a LinkedHashMap object with an optional raw collection and options.
The entryOrRawElements
parameter is an iterable collection of elements. It is
used to initialize the HashMapLinked instance with key-value pairs. Each element in the
entryOrRawElements
is converted to a key-value pair using the toEntryFn
function (if provided) and
then added to the HashMap
Optional
options: LinkedHashMapOptions<K, V, R>The options
parameter is an optional object that can contain the following
properties:
The function returns a record of HashMapLinkedNode objects with string keys.
The method is returning a Record object, which is a TypeScript type that represents an object with string keys and values that are HashMapLinkedNode objects with keys of type K and values of type V or undefined.
The function returns the size of an object.
The size of the object.
Protected
_deleteProtected
_getTime 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(1)
The function at
retrieves the key-value pair at a specified index in a linked list.
The index parameter is a number that represents the position of the element we want to retrieve from the data structure.
The method at(index: number)
is returning an array containing the key-value pair at
the specified index in the data structure. The key-value pair is represented as a tuple [K, V]
,
where K
is the key and V
is the value.
Time Complexity: O(n) Space Complexity: O(n)
The clone
function creates a new instance of a LinkedHashMap
with the same key-value pairs as
the original.
The clone()
method is returning a new instance of LinkedHashMap<K, V>
that is a clone
of the original LinkedHashMap
object.
Time Complexity: O(1) Space Complexity: O(1)
The delete
function removes a key-value pair from a map-like data structure.
The key
parameter is the key that you want to delete from the data structure.
It can be of any type, but typically it is a string or an object.
a boolean value. It returns true
if the deletion was successful, and false
if the key
was not found.
Time Complexity: O(n) Space Complexity: O(1)
The deleteAt
function deletes a node at a specified index in a linked list.
The index parameter represents the position at which the node should be deleted in the linked list.
The size of the list after deleting the element at the specified index.
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 LinkedHashMap
containing key-value pairs from the original
map that satisfy a given predicate function.
The predicate
parameter is a callback function that takes four arguments:
value
, key
, index
, and this
. It should return a boolean value indicating whether the
current element should be included in the filtered map or not.
Optional
thisArg: anyThe thisArg
parameter is an optional argument that allows you to
specify the value of this
within the predicate
function. It is used when you want to bind a
specific object as the context for the predicate
function. If thisArg
is not provided, this @returns a new
LinkedHashMapobject that contains the key-value pairs from the original
LinkedHashMap` object that satisfy the given 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, `
Time Complexity: O(1) Space Complexity: O(1)
The function get
retrieves the value associated with a given key from a map, either by using the
key directly or by using an index stored in the key object.
The key
parameter is the key used to retrieve a value from the map. It can be
of any type, but typically it is a string or symbol.
The value associated with the given key is being returned. If the key is an object key,
the value is retrieved from the _nodes
array using the index stored in the OBJ_KEY_INDEX
property of the key. If the key is a string key, the value is retrieved from the _noObjMap
object
using the key itself. If the key is not found, undefined
is
Time Complexity: O(1) Space Complexity: O(1)
The function checks if a given key exists in a map, using different logic depending on whether the key is a weak key or not.
The key
parameter is the key that is being checked for existence in the map.
The method has
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 LinkedHashMap
by applying a callback function to
each key-value pair in the original map.
The callback parameter is a function that will be called for each key-value pair in the map. It takes four arguments: the value of the current key-value pair, the key of the current key-value pair, the index of the current key-value pair, and the map itself. The callback function should
Optional
thisArg: anyThe thisArg
parameter is an optional argument that allows you to
specify the value of this
within the callback function. If provided, the callback function will
be called with thisArg
as its this
value. If not provided, this
will refer to the current
map
a new LinkedHashMap
object with the values mapped according to 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.
Time Complexity: O(k) Space Complexity: O(k)
The function setMany
takes an iterable collection, converts each element into a key-value pair
using a provided function, and sets each key-value pair in the current object, returning an array
of booleans indicating the success of each set operation.
The setMany
function returns an array of booleans.
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.