mesos-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Park (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (MESOS-4063) Add a filter abstraction to stout
Date Fri, 04 Dec 2015 00:33:10 GMT

    [ https://issues.apache.org/jira/browse/MESOS-4063?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15039495#comment-15039495
] 

Michael Park commented on MESOS-4063:
-------------------------------------

A big question here for me is: What should be the signature of {{filter}}?

I would push for an approach that gives us the high-level abstraction without having to pay
for an unnecessary overload.
One way to do this is to return a *view* of the container with lazy operations applied to
them, e.g., {{boost::adaptors::filter}}.
The result is a range that can be iterated over and can be constructed into whatever container/elements
is desired by the user.

{code}
std::vector<int> v = {1, 2, 3, 1, 2, 3};

// resulting view with a lazy operation applied.
auto range = v | boost::adaptors::filtered([](int x) { return x % 2 != 0; });

// construct a vector
std::vector<int> x(std::begin(range), std::end(range));  // x == {1, 3, 1, 3}

// construct a set
std::set<int> y(std::begin(range), std::end(range));  // y == {1, 3}
{code}

Another approach is to follow the existing pattern in {{stout}} and return values rather than
views. In which case, we need to decide what the returned container is. Would it always be
{{std::vector<T>}}? Would it be deduced by the type of the input container? Would we
require it be explicitly specified? Would we require an output container? How do we know what
the {{push}} operation would be for a container? That is, we could support a closed set of
containers (e.g., {{std::vector/push_back}}, {{std::set/insert}}, {{Resources/operator+=}}),
but I don't think we can be truly generic here.

> Add a filter abstraction to stout
> ---------------------------------
>
>                 Key: MESOS-4063
>                 URL: https://issues.apache.org/jira/browse/MESOS-4063
>             Project: Mesos
>          Issue Type: Wish
>          Components: stout
>            Reporter: Alexander Rukletsov
>            Priority: Minor
>              Labels: mesosphere
>
> Consider a simple snippet which filters agents that satisfy a certain condition:
> {code}
>   foreach (const SlaveID& slaveId, slaveIds_) {
>     if (isWhitelisted(slaveId) && slaves[slaveId].activated) {
>       slaveIds.push_back(slaveId);
>     }
>   }
> {code}
> or using modern C++:
> {code}
>   std::copy_if(
>       slaveIds_.begin(),
>       slaveIds_.end(),
>       std::back_inserter(slaveIds),
>       [this](const SlaveID& slaveId) {
>         return (isWhitelisted(slaveId) && slaves[slaveId].activated);
>       });
> {code}
> Both approaches are not concise and do not clearly explain what the intention is. It
would be great to write something like this instead:
> {code}
> std::vector<SlaveID> slaveIDs = stout::filter(
>     slaveIDs_,
>     [this](const SlaveID& slaveId) {
>       return (isWhitelisted(slaveId) && slaves[slaveId].activated);
>     });
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message