generated from seqan/library-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from eseiler/misc/insert_iterator
[MISC] Allow insert_iterator on std::vector
- Loading branch information
Showing
6 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// -------------------------------------------------------------------------------------------------- | ||
// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin | ||
// Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik | ||
// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License | ||
// shipped with this file and also available at: https://github.com/seqan/raptor/blob/main/LICENSE.md | ||
// -------------------------------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
|
||
#include <algorithm> // for max | ||
#include <cassert> // for assert | ||
#include <cinttypes> // for uint64_t | ||
#include <cstddef> // for ptrdiff_t | ||
#include <iterator> // for output_iterator_tag | ||
#include <utility> // for addressof, move | ||
#include <vector> // for vector | ||
|
||
#include <hibf/contrib/robin_hood.hpp> // for unordered_flat_set | ||
#include <hibf/platform.hpp> | ||
|
||
// IWYU pragma: private, include <hibf/config.hpp> | ||
|
||
namespace seqan::hibf | ||
{ | ||
|
||
class insert_iterator | ||
{ | ||
public: | ||
using iterator_category = std::output_iterator_tag; | ||
using value_type = void; | ||
using difference_type = ptrdiff_t; | ||
using pointer = void; | ||
using reference = void; | ||
|
||
insert_iterator() = delete; | ||
insert_iterator(insert_iterator const &) = default; | ||
insert_iterator(insert_iterator &&) = default; | ||
insert_iterator & operator=(insert_iterator const &) = default; | ||
insert_iterator & operator=(insert_iterator &&) = default; | ||
~insert_iterator() = default; | ||
|
||
explicit constexpr insert_iterator(robin_hood::unordered_flat_set<uint64_t> & set) : | ||
set{std::addressof(set)}, | ||
is_set{true} | ||
{} | ||
|
||
explicit constexpr insert_iterator(std::vector<uint64_t> & vec) : vec{std::addressof(vec)}, is_set{false} | ||
{} | ||
|
||
insert_iterator & operator=(uint64_t const value) noexcept | ||
{ | ||
if (is_set) | ||
{ | ||
assert(set != nullptr); | ||
set->emplace(std::move(value)); | ||
} | ||
else | ||
{ | ||
assert(vec != nullptr); | ||
vec->emplace_back(std::move(value)); | ||
} | ||
return *this; | ||
} | ||
|
||
[[nodiscard]] constexpr insert_iterator & operator*() noexcept | ||
{ | ||
return *this; | ||
} | ||
|
||
constexpr insert_iterator & operator++() noexcept | ||
{ | ||
return *this; | ||
} | ||
|
||
constexpr insert_iterator operator++(int) noexcept | ||
{ | ||
return *this; | ||
} | ||
|
||
private: | ||
robin_hood::unordered_flat_set<uint64_t> * set{nullptr}; | ||
std::vector<uint64_t> * vec{nullptr}; | ||
bool is_set{false}; | ||
}; | ||
|
||
} // namespace seqan::hibf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3458567
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
hibf – ./
hibf-git-main-seqan.vercel.app
hibf-seqan.vercel.app
hibf.vercel.app