Discussion:
Propose new type of collection: PrefixMap
Niels Basjes
2018-11-30 21:42:45 UTC
Permalink
Hi,

I was working on a project ( https://github.com/nielsbasjes/yauaa )
where I ran into the situation that I needed a type of collection that
was not yet present in either Java or commons-collections.

So I wrote my own implementation and I think this may be a useful
addition to commons-collections.

At this point we have
- the Map that allows retrieval of a single value based on an exact key.
- the Trie that allows retrieval of a set of values based where the
keys all start with the same prefix.

What I needed a structure where it holds the prefixes and associated
values and I want to retrieve the 'best matching prefix' for a given
input.

To illustrate what I mean using the original use case:
PrefixMap<String> prefixMap = new ASCIIPrefixMap<>(false); // false ==
match case insensitive
prefixMap.put("SM-", "Samsung");
prefixMap.put("Mi-", "Xiaomi");
prefixMap.getLongestMatch("SM-1234"); // ---> "Samsung"

I propose to make a PrefixMap interface and then add the two
implementations I have created separately.

For now I have called this a PrefixMap and I want to know if you agree
this would be a useful addition.
--
Best regards / Met vriendelijke groeten,

Niels Basjes
Committer/PMC Apache Avro

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-***@commons.apache.org
For additional commands, e-mail: dev-***@commons.apache.org
Loading...