collections.js - differance between SortedMap and SortedArrayMap

Viewed 58

I was searching for a sorted map in javascript and found collections.js's implementation - SortedMap. I also see that they have something called SortedArrayMap.

In the description of SortedArrayMap it says:

A map of key value pairs, sorted by key, backed by an array.

(Source)

And in the description of SortedMap it says:

A map with entries sorted by key.

What exactly does backed by an array mean? and what is the difference between it and the normal SortedMap?

2 Answers

At first glance, SortedArrayMap uses a binary search strategy to maintain the order of the entries and is backed by an array, which means that use an array as a basic data structure(to maintain data of key). So that means in the end, that it uses a map based on SortedArray class.

However, SortedMap is a general key/value collection, where you can access values with their relative key(quick access rather than an array order).

Anyway, if you want to dive a bit more into this topic, you can find a very good explanation on the is the official website of collections.js,

As stated on http://www.collectionsjs.com/map, maps are different as they work like dictionaries but accepting even objects as a key.

Reading the Dict documentation on http://www.collectionsjs.com/dict we understand that:

A dictionary is a specialized map. The keys are required to be strings.

An array is simply a data structure where you can insert anything using a simple push(thingToInsert). Items inserted into an Array are just values without a key to point to them.

Related