5a42e15c4a
Squashed messages from 9 commits: 9. Properties now uses PropertyFamily and contained classes. Fetching,seting,clearing properties can be done with PropertyFamilyKey or PropertyTypeKey. Hierarchy of newly added clases is: Vertices -n-> PropertyFamily {name: String} <-1-n-> PropertyType {type: Property::Flags} Edges -n-> PropertyFamily {name: String} <-1-n-> PropertyType {type: Property::Flags} PropertyFamilyKey -> PropertyType PropertyTypeKey -> PropertyType PropertyType t0,t1; let t0!=t1 be true let t0.family==t1.family be true then next is true PropertyTypeKey{&t0}!=PropertyTypeKey{&t1} PropertyFamilyKey{&t0}==PropertyFamilyKey{&t1} PropertyFamilyKey{&t0}==PropertyTypeKey{&t1} PropertyTypeKey{&t0}==PropertyFamilyKey{&t1} 8. Intermedate commit. Noticed that integration queries throw SEGFAULT. 7. Defined interface for indexes. Fixed three memory leaks. Fixed integration_queries test which now passes. 6. Commit which return Xorshift128plus to valid shape. 5. Tmp commit. 4. Label Index is compiling. 3. tmp 2. Vertex::Accessor now updates Label index. 1. Applied changes for code review.
49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "utils/iterator/iterator_base.hpp"
|
|
#include "utils/option.hpp"
|
|
|
|
namespace iter
|
|
{
|
|
|
|
// Class which maps values returned by I iterator into value of type T with OP
|
|
// function.
|
|
// T - type of return value
|
|
// I - iterator type
|
|
// OP - type of mapper function
|
|
template <class T, class I, class OP>
|
|
class Map : public IteratorBase<T>
|
|
{
|
|
|
|
public:
|
|
Map() = delete;
|
|
|
|
// Map operation is designed to be used in chained calls which operate on a
|
|
// iterator. Map will in that usecase receive other iterator by value and
|
|
// std::move is a optimization for it.
|
|
Map(I &&iter, OP &&op) : iter(std::move(iter)), op(std::move(op)) {}
|
|
|
|
Option<T> next() final
|
|
{
|
|
auto item = iter.next();
|
|
if (item.is_present()) {
|
|
return Option<T>(op(item.take()));
|
|
} else {
|
|
return Option<T>();
|
|
}
|
|
}
|
|
|
|
private:
|
|
I iter;
|
|
OP op;
|
|
};
|
|
|
|
template <class I, class OP>
|
|
auto make_map(I &&iter, OP &&op)
|
|
{
|
|
// Compiler cant deduce type T. decltype is here to help with it.
|
|
return Map<decltype(op(iter.next().take())), I, OP>(std::move(iter),
|
|
std::move(op));
|
|
}
|
|
}
|