This data structure has two strong properties:
1- guaranteed uniqueness of its elements.
2- preservation of insertion order of its elements.
The combination of these properties will allow simplification of a lot of algorithm.
Expl:
While creating a dependency graph. You want to memoize the elements of the current branch you are traversing, and at the same time catch cyclic dependency. Very useful.
‐---------
hashed_stack | depends on
[main] | fileB , fileC, fileD
[fileB] | file1 , file2, file3
[file1] | file# , file@, fileB <-- cyclic dep
Instead of maintaining two data structures, a hash and stack, you have both in the same container.
And you can adopt this implementation to other ordered containers, like a queue:.
std::hashed_queue
-------- Original message --------
From: Jason McKesson via Std-Proposals <std-proposals@lists.isocpp.org>
Date: 1/4/24 12:02 AM (GMT+04:00)
To: std-proposals@lists.isocpp.org
Cc: Jason McKesson <jmckesson@gmail.com>
Subject: Re: [std-proposals] New Data structure.
On Wed, Jan 3, 2024 at 2:48 PM organicoman via Std-Proposals
<std-proposals@lists.isocpp.org> wrote:
>
> Hello Gents,
> I would like to suggest a new data structure that combines 'std::unordered_set' and a 'std::stack' behavior.
> I will refere to it as 'std::hashed_stack'.
>
> Important methods of 'std::hashed_stack' container are:
>
> -'push': to insert a key, and if it already exists nothing will happen.
>
> -'pop': to extract the last key inserted.
But not the last key *pushed* if it was already in the container? That
sounds *really* weird. What's the use case for this data structure?
In fact, I'm not sure when I would want either behavior. If I'm using
a thing that calls itself a "stack," the idea that `push` and `pop`
should be balanced is non-negotiable. That's what makes it a *stack*.
The possibility that pushing two things and poping once could result
in a balanced stack is... bizarre.
If I push a thing twice, I should have to pop it twice, even if it's
the same thing and takes up the same space in the stack's storage.
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals