C++ Logo

std-proposals

Advanced search

Re: [std-proposals] New Data structure.

From: organicoman <organicoman_at_[hidden]>
Date: Thu, 04 Jan 2024 00:26:55 +0400
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 depInstead 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_queueSent from my Galaxy
-------- Original message --------From: Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> Date: 1/4/24 12:02 AM (GMT+04:00) To: std-proposals_at_[hidden] Cc: Jason McKesson <jmckesson_at_[hidden]> Subject: Re: [std-proposals] New Data structure. On Wed, Jan 3, 2024 at 2:48 PM organicoman via Std-Proposals<std-proposals_at_[hidden]> 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? Thatsounds *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 usinga 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 resultin a balanced stack is... bizarre.If I push a thing twice, I should have to pop it twice, even if it'sthe same thing and takes up the same space in the stack's storage.-- Std-Proposals mailing listStd-Proposals_at_[hidden]://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-01-03 20:27:03