@@ -7,58 +7,92 @@ export class NFTMap<V> {
77 this . _map = new Map ( ) ;
88 }
99
10- // Helper function to convert an NFT to its string representation
10+ /**
11+ * Converts an NFT object into a string representation for use as a key in the map.
12+ * @param nft - The NFT to convert to a key.
13+ * @returns {string } - The string representation of the NFT (globalId).
14+ */
1115 private toMapKey ( nft : NFT ) : string {
1216 return nft . globalId ( ) ;
1317 }
1418
15- // Sets the value for a given NFT key
19+ /**
20+ * Sets the value for a given NFT key.
21+ * @param nft - The NFT key.
22+ * @param value - The value to associate with the NFT key.
23+ */
1624 set ( nft : NFT , value : V ) : void {
1725 this . _map . set ( this . toMapKey ( nft ) , value ) ;
1826 }
1927
20- // Gets the value for a given NFT key
28+ /**
29+ * Gets the value associated with a given NFT key.
30+ * @param nft - The NFT key.
31+ * @returns - The value associated with the NFT key, or undefined if the key is not present.
32+ */
2133 get ( nft : NFT ) : V | undefined {
2234 return this . _map . get ( this . toMapKey ( nft ) ) ;
2335 }
2436
25- // Checks if the map contains the given NFT key
37+ /**
38+ * Checks if the map contains the given NFT key.
39+ * @param nft - The NFT key.
40+ * @returns - True if the map contains the NFT key, otherwise false.
41+ */
2642 has ( nft : NFT ) : boolean {
2743 return this . _map . has ( this . toMapKey ( nft ) ) ;
2844 }
2945
30- // Deletes a key-value pair by the given NFT key
46+ /**
47+ * Deletes the entry associated with a given NFT key.
48+ * @param nft - The NFT key.
49+ * @returns - True if the entry was successfully deleted, otherwise false.
50+ */
3151 delete ( nft : NFT ) : boolean {
3252 return this . _map . delete ( this . toMapKey ( nft ) ) ;
3353 }
3454
35- // Clears the entire map
55+ /**
56+ * Clears all entries from the map.
57+ */
3658 clear ( ) : void {
3759 this . _map . clear ( ) ;
3860 }
3961
40- // Returns the number of key-value pairs in the map
62+ /**
63+ * Returns the number of entries in the map.
64+ * @returns {number } - The size of the map.
65+ */
4166 size ( ) : number {
4267 return this . _map . size ;
4368 }
4469
45- // Iterates through the map and applies the callback function to each entry
70+ /**
71+ * Iterates through the map and applies a callback function to each entry.
72+ * @param {Function } callback - A function that takes the value and NFT key as arguments.
73+ */
4674 forEach ( callback : ( value : V , nft : NFT ) => void ) : void {
4775 this . _map . forEach ( ( value , key ) => {
4876 const nft = NFT . fromGlobalId ( key ) ;
4977 callback ( value , nft ) ;
5078 } ) ;
5179 }
5280
53- // Converts the map back into an array of [NFT, V] pairs
81+ /**
82+ * Converts the map into an array of [NFT, V] pairs.
83+ * @returns {[NFT, V][] } - An array of [NFT, V] pairs.
84+ */
5485 toArray ( ) : [ NFT , V ] [ ] {
5586 return Array . from ( this . _map ) . map ( ( [ key , value ] ) => [
5687 NFT . fromGlobalId ( key ) ,
5788 value ,
5889 ] ) ;
5990 }
6091
61- // Returns a string representation of the map (optional)
92+ /**
93+ * Returns a string representation of the map.
94+ * @returns {string } - A string representation of the map's key-value pairs.
95+ */
6296 toString ( ) : string {
6397 return `{${ Array . from ( this . _map )
6498 . map ( ( [ key , value ] ) => `${ key } : ${ value } ` )
0 commit comments