Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #170 Get map size

Set n to the number of elements stored in mymap.

This is not always equal to the map capacity.

(def n (count mymap))
auto n = mymap.size();
n = mymap.Count;
const n = mymap.length;
n := len(mymap)
import qualified Data.Map as Map
getMapSize :: Map.Map k v -> Int
getMapSize m = Map.size m
const length = map.size
int n = mymap.size();
$n = count($mymap);
fgl
n := MyMap.Count;
my $n = %mymap;
n = len(mymap)
n = mymap.size
let n = mymap.len();
val n = mymap.size

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms