concurrent_unordered_map テンプレート・クラスと concurrent_unordered_multimap テンプレート・クラス

概要

挿入および全検索の並列操作をサポートする結合コンテナー用のテンプレート・クラス。

構文

template <typename Key,
             typename Element,
             typename Hasher = tbb_hash<Key>,
             typename Equality = std::equal_to<Key>,
             typename Allocator = tbb::tbb_allocator<std::pair<const Key, Element> > >
class concurrent_unordered_map;
template <typename Key,
             typename Element,
             typename Hasher = tbb_hash<Key>,
             typename Equality = std::equal_to<Key>,
             typename Allocator = tbb::tbb_allocator<std::pair<const Key, Element> > >
class concurrent_unordered_multimap;

ヘッダー

#include "tbb/concurrent_unordered_map.h"

説明

concurrent_unordered_mapconcurrent_unordered_multimap は、挿入と全検索の並列操作はサポートしていますが、消去の並列操作はサポートしていません。インターフェイスには使用可能なロックはありません。内部的にロックを保持している可能性はありますが、ユーザー定義コードの呼び出し中にロックが保持されることはありません。次の点を除いて、それぞれ C++11 の std::unordered_mapstd::unordered_multimap のセマンティクスと似ています。

次の表は、concurrent_unordered_map クラス、concurrent_hash_map クラス、concurrent_unordered_multimap クラスの重要な違いを示したものです。

クラス

重要な違い

concurrent_hash_map

消去操作を同時に処理でき、ビルトインのロックがあります。

concurrent_unordered_map

  • 全検索操作と挿入操作を同時に処理できます。使用可能なロックはなく、C++11 の unordered_map によく似ています。

  • [ ] アクセサーと at アクセサーがあります。

concurrent_unordered_multimap

  • concurrent_unordered_multimap では、同じ key 値の複数の <key,value> ペアが挿入される可能性があります。

  • find は、検索時に最初に見つかった key の一致する <key,value> ペアを返します。ただし、そのペアが返される前に、コンテナーへの同時アクセスにより、同じ key の別のペアが挿入される可能性があります。

注意

ほかのハッシュテーブルと同様に、等価なキーのハッシュコードは同じでなければなりません。理想的なハッシュ関数は、キーをハッシュコード空間に均等に分散します。

concurrent_unordered_map と concurrent_unordered_multimap の共通のメンバー

次のコード例で、太字 のメソッドは同時に呼び出すことができます。 例えば、3 つの異なるスレッドが insertbegin、および size を同時に呼び出すことができます。それぞれの結果は非決定的です。例えば、size の結果は insert 操作の前後では異なります。

public:
    // 型
    typedef Key key_type;
    typedef std::pair<const Key, T> value_type;
    typedef Element mapped_type;
    typedef Hash hasher;
    typedef Equality key_equal;
    typedef Alloc allocator_type;
    typedef typename allocator_type::pointer pointer;
    typedef typename allocator_type::const_pointer const_pointer;
    typedef typename allocator_type::reference reference;
    typedef typename allocator_type::const_reference const_reference;
    typedef implementation-defined size_type;
    typedef implementation-defined difference_type;
    typedef implementation-defined iterator;
    typedef implementation-defined const_iterator;
    typedef implementation-defined local_iterator;
    typedef implementation-defined const_local_iterator;

    allocator_type get_allocator() const;

    // サイズとキャパシティー
    bool empty() const;     // リニア時間になる!
    size_type size() const; // リニア時間になる!
    size_type max_size() const;

    // イテレーター
    iterator begin();
    const_iterator begin() const;
    iterator end();
    const_iterator end() const;
    const_iterator cbegin() const;
    const_iterator cend() const;
  
    // 修飾子
    std::pair<iterator, bool> insert(const value_type& x);
    iterator insert(const_iterator hint, const value_type& x);
    template<class InputIterator>
    void insert(InputIterator first, InputIterator last);
    // C++11 仕様
    std::pair<iterator, bool> insert(value_type&& x);
    iterator insert(const_iterator hint, value_type&& x);    
    void insert(std::initializer_list<value_type> il);
    // C++11 仕様
    template<typename... Args>
    std::pair<iterator, bool> emplace(Args&&... args);
    template<typename... Args>
    iterator emplace_hint(const_iterator hint, Args&&... args);
      
    iterator unsafe_erase(const_iterator position);
    size_type unsafe_erase(const key_type& k);
    iterator unsafe_erase(const_iterator first, const_iterator last);
    void clear();

    // オブザーバー
    hasher hash_function() const;
    key_equal key_eq() const;

    // ルックアップ
    iterator find(const key_type& k);
    const_iterator find(const key_type& k) const;
    size_type count(const key_type& k) const;
    std::pair<iterator, iterator> equal_range(const key_type& k);
    std::pair<const_iterator, const_iterator> equal_range(const key_type& k) const;

    // 並列反復
    typedef implementation-defined range_type;
    typedef implementation-defined const_range_type;
    range_type range();
    const_range_type range() const;

    // バケット・インターフェイス - デバッグ用
    size_type unsafe_bucket_count() const;
    size_type unsafe_max_bucket_count() const;
    size_type unsafe_bucket_size(size_type n);
    size_type unsafe_bucket(const key_type& k) const;
    local_iterator unsafe_begin(size_type n);
    const_local_iterator unsafe_begin(size_type n) const;
    local_iterator unsafe_end(size_type n);
    const_local_iterator unsafe_end(size_type n) const;
    const_local_iterator unsafe_cbegin(size_type n) const;
    const_local_iterator unsafe_cend(size_type n) const;

    // ハッシュポリシー
    float load_factor() const;
    float max_load_factor() const;
    void max_load_factor(float z);
    void rehash(size_type n);

concurrent_unordered_map のメンバー

次のコード例で、太字のメソッドは同時に呼び出すことができます。

public:
    // 構築、破棄、コピー
    explicit concurrent_unordered_map(size_type n = implementation-defined,
    const Hasher& hf = hasher(),
    const key_equal& eql = key_equal(),
    const allocator_type& a = allocator_type());
    template <typename InputIterator>
    concurrent_unordered_map(InputIterator first, InputIterator last,
                              size_type n = implementation-defined,
                              const hasher& hf = hasher(),
                              const key_equal& eql = key_equal(),
                              const allocator_type& a = allocator_type());
    concurrent_unordered_map(const concurrent_unordered_map&);
    concurrent_unordered_map(const Alloc&);
    concurrent_unordered_map(const concurrent_unordered_map&, const Alloc&);
    // C++11 仕様
    concurrent_unordered_map(concurrent_unordered_map&&);
    concurrent_unordered_map(concurrent_unordered_map&&, const Allocator&);
    concurrent_unordered_map(std::initializer_list<value_type> il,
                              size_type n = implementation-defined,
                              const Hasher& hf = hasher(),
                              const key_equal& eql = key_equal(),
                              const allocator_type& a = allocator_type());
    ~concurrent_unordered_map();

    concurrent_unordered_map& operator=(const concurrent_unordered_map&);
    // C++11 仕様
    concurrent_unordered_map& operator=(concurrent_unordered_map&&);
    concurrent_unordered_map& operator=(std::initializer_list<value_type> il);

    void swap(concurrent_unordered_map&);

    mapped_type& operator[](const key_type& k);
    mapped_type& at( const key_type& k );
    const mapped_type& at(const key_type& k) const;

concurrent_unordered_multimap のメンバー

public:
    // 構築、破棄、コピー
    explicit concurrent_unordered_multimap(size_type n = implementation-defined,
                                           const Hasher& hf = hasher(),
                                           const key_equal& eql = key_equal(),
                                           const allocator_type& a = allocator_type());
    template <typename InputIterator>
    concurrent_unordered_multimap( InputIterator first, InputIterator last,
                                   size_type n = implementation-defined,
                                   const hasher& hf = hasher(),
                                   const key_equal& eql = key_equal(),
                                   const allocator_type& a = allocator_type());
    concurrent_unordered_multimap(const concurrent_unordered_multimap&);
    concurrent_unordered_multimap(const Alloc&);
    concurrent_unordered_multimap(const concurrent_unordered_multimap&, const Alloc&);
    // C++11 仕様
    concurrent_unordered_multimap(concurrent_unordered_multimap&&);
    concurrent_unordered_multimap(concurrent_unordered_multimap&&, const Allocator&);
    concurrent_unordered_multimap(std::initializer_list<value_type> il,
                                  size_type n = implementation-defined,
                                  const Hasher& hf = hasher(),
                                  const key_equal& eql = key_equal(),
                                  const allocator_type& a = allocator_type());
    ~concurrent_unordered_multimap();

    concurrent_unordered_multimap& operator=(const concurrent_unordered_multimap&);
    // C++11 仕様
    concurrent_unordered_multimap& operator=(concurrent_unordered_multimap&&);
    concurrent_unordered_multimap& operator=(std::initializer_list<value_type> il);

    void swap(concurrent_unordered_multimap&);

関連情報