Home > Back-end >  STD there is a similar sort of thing
STD there is a similar sort of thing

Time:10-28

Memory management probably tens of millions of people, the amount of money each wallet, and in a dynamic change, I just want to use the fastest speed to find a moment ago ten billionaires, STD what's inside the appropriate data structure to deal with it? Himself as a data structure is easy, use SQL easier, but I wanted to know STD inside have ready

CodePudding user response:

Consider using the VECTOR container support, according to custom rules automatic sorting

CodePudding user response:

 # include & lt; Iostream> 
# include & lt; Cstdlib>
# include & lt; Climits>

Int main ()
{
Int a []={2, 99, 0, 743, 2, INT_MIN, 4};
Constexpr STD: : size_t size=sizeof a/sizeof * a;

STD: : tree (a, a, the size, sizeof * [] (const void * a, const void * b)
{
Int arg1=* static_cast & lt; Const int * & gt; (a);
Int arg2=* static_cast & lt; Const int * & gt; (b);

If (arg1 & lt; Arg2) return 1;
If (arg1 & gt; Arg2) return 1;
return 0;

//return (arg1 & gt; Arg2) - (arg1 & lt; Arg2);//the abbreviation of feasible
//return arg1, arg2;//the abbreviation of errors (if any INT_MIN failure)
});

For (int ai: a)
STD: : cout & lt; & lt; Ai & lt; & lt; "';
}

CodePudding user response:

Because I just want to find tens of millions of data inside a few, so if you are looking for, to do the sorting, then the price of article to a few data sorting tens of millions of data is quite large, so I hope the best this container is orderly, and can dynamically when modify the value to be able to be orderly, STD does not have the appropriate container, if not I will be the

CodePudding user response:

STD: : set
STD: : map

CodePudding user response:

reference bluebohe reply: 3/f
because I just want to find tens of millions of data inside a few, so if you are looking for, to do the sorting, then the price of article to a few data sorting tens of millions of data is quite large, so I hope the best this container is orderly, and can dynamically when modify the value to be able to be orderly, STD does not have the appropriate container, if not I will be the

Java treeset can, but there is no
c + +Whether you're using SQL or what, all need to sorting, just SQL is a database to help you sort
Or you can do a cache, a few records before data changes will compare with the record of the cache (greater than the cached data exchange), always keep a register of cache is the latest high

CodePudding user response:

reference 4 floor _mervyn response:
STD: : set
STD: : map


The first key can't repeat, then changed the money can't do

CodePudding user response:

The inside of the STL priority queue, priority_queue

CodePudding user response:

refer to 6th floor bluebohe response:
Quote: refer to 4th floor _mervyn response:
STD: : set
STD: : map


The first key can't repeat, then changed the money can't do


The STD: : multiset or STD: : multimap,,,, money, for the key, every time want to change money, first take out the corresponding elements to insert again, after,

I feel or look at your application is "query top ten billionaires" high frequency, or "change money" high frequency,

CodePudding user response:

STD: : n_th, off-the-shelf
  • Related