World Conquest Chronicles

World Conquest Chronicles

go-hashmap, v1.3

The library that implements a hash map with synchronized and concurrent wrappers.

Support randomizing of iteration order.

Change Log

  • support randomizing of iteration order:
    • for a hash map:
      • over items and their keys;
    • for a synchronized hash map:
      • over items and their keys;
    • for a concurrent hash map:
      • over items and their keys;
      • over shards.

Features

  • implementation of a hash map:
    • use the open addressing strategy for collision resolution;
    • use the key interface for supporting custom types;
    • support operations:
      • getting of an item by a key;
      • iteration over items and their keys:
        • support stopping of iteration;
        • support randomizing of iteration order;
      • setting of an item by a key;
      • deleting of an item by a key;
  • implementation of a synchronized hash map:
    • use the implementation described above as an inner map;
    • use a mutex lock to access the inner map;
    • support operations:
      • getting of an item by a key;
      • iteration over items and their keys:
        • support stopping of iteration;
        • support randomizing of iteration order;
      • setting of an item by a key;
      • deleting of an item by a key;
  • implementation of a concurrent hash map:
    • use data sharding for concurrent access;
    • use the synchronized implementation described above as one shard;
    • support operations:
      • getting of an item by a key;
      • iteration over items and their keys:
        • support stopping of iteration;
        • support randomizing of iteration order:
          • over items and their keys;
          • over shards;
      • setting of an item by a key;
      • deleting of an item by a key.

Benchmarks

SynchronizedHashMap & ConcurrentHashMap

BenchmarkSynchronizedBuiltinMap/Iterate/1000/1-8           50000         31765 ns/op          16 B/op          1 allocs/op
BenchmarkSynchronizedBuiltinMap/Iterate/1000/10-8           3000        432350 ns/op          16 B/op          1 allocs/op
BenchmarkSynchronizedBuiltinMap/Iterate/1000/100-8           300       4324755 ns/op          16 B/op          1 allocs/op
BenchmarkSynchronizedBuiltinMap/Iterate/1000/1000-8           30      42040394 ns/op          16 B/op          1 allocs/op
BenchmarkSyncMap/Iterate/1000/1-8                          50000         23365 ns/op          16 B/op          1 allocs/op
BenchmarkSyncMap/Iterate/1000/10-8                         10000        121205 ns/op          16 B/op          1 allocs/op
BenchmarkSyncMap/Iterate/1000/100-8                         2000        597609 ns/op          16 B/op          1 allocs/op
BenchmarkSyncMap/Iterate/1000/1000-8                         300       4425533 ns/op          16 B/op          1 allocs/op
BenchmarkSynchronizedHashMap/Iterate/1000/1-8              10000        158704 ns/op       16400 B/op          2 allocs/op
BenchmarkSynchronizedHashMap/Iterate/1000/10-8              1000       2202094 ns/op      163873 B/op         11 allocs/op
BenchmarkSynchronizedHashMap/Iterate/1000/100-8               30      50536697 ns/op     1639883 B/op        123 allocs/op
BenchmarkSynchronizedHashMap/Iterate/1000/1000-8               5     285370312 ns/op    16455260 B/op       2047 allocs/op
BenchmarkConcurrentHashMap/Iterate/1000/1-8                10000        159969 ns/op       16528 B/op         18 allocs/op
BenchmarkConcurrentHashMap/Iterate/1000/10-8                1000       1827186 ns/op      165231 B/op        171 allocs/op
BenchmarkConcurrentHashMap/Iterate/1000/100-8                 30      37668533 ns/op     1653639 B/op       1715 allocs/op
BenchmarkConcurrentHashMap/Iterate/1000/1000-8                 5     301812861 ns/op    16614966 B/op      18548 allocs/op

HashMap

BenchmarkBuiltinMap/Iterate/10-8            10000000           154 ns/op           0 B/op          0 allocs/op
BenchmarkBuiltinMap/Iterate/100-8            1000000          1385 ns/op           0 B/op          0 allocs/op
BenchmarkBuiltinMap/Iterate/1000-8            100000         16589 ns/op           0 B/op          0 allocs/op
BenchmarkBuiltinMap/Iterate/10000-8            10000        155178 ns/op           0 B/op          0 allocs/op
BenchmarkBuiltinMap/Iterate/100000-8            1000       1543827 ns/op           0 B/op          0 allocs/op
BenchmarkBuiltinMap/Iterate/1000000-8            100      19472155 ns/op           0 B/op          0 allocs/op
BenchmarkHashMap/Iterate/10-8                2000000           756 ns/op         128 B/op          1 allocs/op
BenchmarkHashMap/Iterate/100-8                100000         11356 ns/op        2048 B/op          1 allocs/op
BenchmarkHashMap/Iterate/1000-8                20000         93844 ns/op       16384 B/op          1 allocs/op
BenchmarkHashMap/Iterate/10000-8                2000        859213 ns/op      131072 B/op          1 allocs/op
BenchmarkHashMap/Iterate/100000-8                 50      20961293 ns/op     2097152 B/op          1 allocs/op
BenchmarkHashMap/Iterate/1000000-8                 5     341586045 ns/op    16777216 B/op          1 allocs/op

Repository

Link: https://github.com/thewizardplusplus/go-hashmap/tree/v1.3.

Content: code.

License: MIT.