<commit_before>
======================
Map Classes
======================

HashMap
========

HashMap class based implementation of the IMap interface.

Hash map uses a hash function to compute an index into an array of slots, from which the desired value can be found. Internally, the elements are not sorted 
in any particular order, but organized into slot. Which slot an element is placed into depends entirely on the hash of its key.

TreeMap
========

TreeMap class based implementation of the IMap interface.

TreeMap is based on Red-Black tree. It provides an efficient means of sorting key/value pairs in sorted order. 
TreeMap class implements Map interface similar to HashMap. The main difference between them is that HashMap is an unordered collection while TreeMap is sorted 
in the ascending order of its keys.

ListMap
========

ListMap class based implementation of the IMap interface.

ListMap is a generic key->value mapping data structure that is designed to be more memory efficient than a HashMap. It keeps its mappings in an array data structure -- 
an integer array of hash codes for each item, and an Object array of the key/value pairs. This allows it to avoid having to create an extra object for every entry 
put into the map, and it also tries to control the growth of the size of these arrays more aggressively.

Map
====

Map<K, V>, internally, contains only Ref<IMap<K, V>> member variable, so it can be used as reference variables in any scope, and also used as function argument and return type.

Adding & Removing Elements
=============================================

You can add and remove elements using put() and remove() methods.

::

   Map<String, String> capitals;
   capitals.put("China", "Beijing");
   capitals.put("Spain", "Madrid");
   capitals.put("United Kingdom", "London");
   capitals.put("United States of America", "Washington, D.C.");
   capitals.remove("Spain");

Reading from a Map
====================

You can use [] operator to access the value for a key. The getValue() method is the other common way to access values.

::

   Map<String, String> capitals;
   capitals.put("China", "Beijing");
   capitals.put("Spain", "Madrid");
   capitals.put("United Kingdom", "London");
   capitals.put("United States of America", "Washington, D.C.");
   
   auto capitalOfSpain = capitals["Spain"];
   String capitalOfChina =  capitals.getValue("China");

Enumerating Maps
=================

Range-based for loop is the most efficient way to enumerate a Map.

::

   Map<String, String> capitals;
   capitals.put("China", "Beijing");
   capitals.put("Spain", "Madrid");
   capitals.put("United Kingdom", "London");
   capitals.put("United States of America", "Washington, D.C.");

   for (String item : capitals) {
      Console::println("%s", item.key);
   }

You can isolate a Map's keys/values with the getAllKeys()/getAllValues() methods.

::

   List<String> keys = capitals.getAllKeys();
   List<String> values = capitals.getAllValues();

Combining Maps
===============

Map object can be expanded by adding the conents of another Map to its collection via the putAll() methods.

::

   Map<String, String> capitals;
   capitals.put("China", "Beijing");
   capitals.put("Japan", "Tokyo");
   capitals.put("Singapore", "Singapore");
   capitals.put("Malaysia", "Kuala Lumpur");

   Map<String, String> others;
   others.put("Spain", "Madrid");<commit_msg>Update Index.rst<commit_after>
======================
Map Classes
======================

HashMap
========

HashMap class based implementation of the IMap interface.

Hash map uses a hash function to compute an index into an array of slots, from which the desired value can be found. Internally, the elements are not sorted 
in any particular order, but organized into slot. Which slot an element is placed into depends entirely on the hash of its key.

TreeMap
========

TreeMap class based implementation of the IMap interface.

TreeMap is based on Red-Black tree. It provides an efficient means of sorting key/value pairs in sorted order. 
TreeMap class implements Map interface similar to HashMap. The main difference between them is that HashMap is an unordered collection while TreeMap is sorted 
in the ascending order of its keys.

ListMap
========

ListMap class based implementation of the IMap interface.

ListMap is a generic key->value mapping data structure that is designed to be more memory efficient than a HashMap. It keeps its mappings in an array data structure -- 
an integer array of hash codes for each item, and an Object array of the key/value pairs. This allows it to avoid having to create an extra object for every entry 
put into the map, and it also tries to control the growth of the size of these arrays more aggressively.

Map
====

Map<K, V>, internally, contains only Ref<IMap<K, V>> member variable, so it can be used as reference variables in any scope, and also used as function argument and return type.

Adding & Removing Elements
=============================================

You can add and remove elements using put() and remove() methods.

.. code-block:: cpp

   Map<String, String> capitals;
   capitals.put("China", "Beijing");
   capitals.put("Spain", "Madrid");
   capitals.put("United Kingdom", "London");
   capitals.put("United States of America", "Washington, D.C.");
   capitals.remove("Spain");

Reading from a Map
====================

You can use [] operator to access the value for a key. The getValue() method is the other common way to access values.

.. code-block:: cpp

   Map<String, String> capitals;
   capitals.put("China", "Beijing");
   capitals.put("Spain", "Madrid");
   capitals.put("United Kingdom", "London");
   capitals.put("United States of America", "Washington, D.C.");
   
   auto capitalOfSpain = capitals["Spain"];
   String capitalOfChina =  capitals.getValue("China");

Enumerating Maps
=================

Range-based for loop is the most efficient way to enumerate a Map.

.. code-block:: cpp

   Map<String, String> capitals;
   capitals.put("China", "Beijing");
   capitals.put("Spain", "Madrid");
   capitals.put("United Kingdom", "London");
   capitals.put("United States of America", "Washington, D.C.");

   for (String item : capitals) {
      Console::println("%s", item.key);
   }

You can isolate a Map's keys/values with the getAllKeys()/getAllValues() methods.

.. code-block:: cpp

   List<String> keys = capitals.getAllKeys();
   List<String> values = capitals.getAllValues();

Combining Maps
===============

Map object can be expanded by adding the conents of another Map to its collection via the putAll() methods.

.. code-block:: cpp

   Map<String, String> capitals;
   capitals.put("China", "Beijing");
   capitals.put("Japan", "Tokyo");
   capitals.put("Singapore", "Singapore");
   capitals.put("Malaysia", "Kuala Lumpur");

   Map<String, String> others;
   others.put("Spain", "Madrid");
{'fraction_non_alphanumeric': 0.1398378691372322, 'fraction_numerical': 0.0, 'mean_word_length': 4.406103286384977, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7579699', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1835, 'n_words': 828}