// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.data.access.helpers; import com.yahoo.collections.Hashlet; import java.util.Collection; import java.util.IdentityHashMap; import java.util.function.Function; /** * Helper class to remove (filter) some names from a Hashlet * @author arnej */ public class MatchFeatureFilter implements Function, Hashlet> { private final IdentityHashMap, Hashlet> mappings = new IdentityHashMap<>(); private final Collection removeList; public MatchFeatureFilter(Collection removeList) { this.removeList = removeList; } Hashlet filter(Hashlet input) { Hashlet result = new Hashlet<>(); result.reserve(input.size()); for (int i = 0; i < input.size(); i++) { String k = input.key(i); if (! removeList.contains(k)) { Integer v = input.value(i); result.put(k, v); } } return result; } public Hashlet apply(Hashlet input) { return mappings.computeIfAbsent(input, k -> filter(k)); } }