« first day (1246 days earlier)      last day (1590 days later) » 

1:39 AM
6
Q: Why is an STL deque not implemented as just a circular vector?

Zhuoran HeI always thought that in C++ standard template library (STL), a double-ended queue (deque) is a size-variable array (like a vector) with circular boundary conditions, meaning there's a head pointer i and a tail pointer j both pointing to some position of an array a[0..L-1]. A push_front is i--, a...

As the accepted answer describes, with so much more complex work to do, the only advantage I get from not choosing a circular vector, is a 2(constant) times faster adding/removing elements performance?
 
 
4 hours later…
5:53 AM
Ok. I accept the accepted answer and the allocate/deallocate advantage is firm enough to choose a different structure from a circular vector(array).
I found another more detailed answer here and it persuaded me. stackoverflow.com/a/14335740/5983841
 
 
3 hours later…
8:45 AM
MSVC searches also the opened header files in reverse order. what! XD
 
9:26 AM
Just wondering if the author made a mistake in this github repo:
`/// Set your CPU's L1 data cache size (in bytes) here
const int64_t L1D_CACHE_SIZE = 32768;`
Cache is normally in the order of kilobytes. I'm guessing 32768 should have 3 zeros at the end?
 
9:47 AM
@northerner why? that is 32K
adding another 3 zeros would make it around 32Megs which is ambitious for a L1 data-cache
well people commonly interchange KiB and KB
 
AAB
Hi all,
 
most of the time people mean KiB
why would a processor use a non-power of two scale?
that would be wasted adressing space
 
AAB
Have a few questions about json
say I have json file read its contents update a key
When the json is written to file
what happens?
 
depends on the json library, most of the time the full file will be re-written
 
AAB
Does the file write the entire JSON string read from the file or does it do an lssek and modify some portion?
@PeterT thanks
Is it even possible to do a lseek and write contents to file.
?
Apart from that say I want to map a key to some value like 1234 -> Bangalore
 
9:55 AM
I mean yeah you can seek to it, but you will need to write the rest of the whole file from that point on
unless what you replace is exactly as long as the previous key
 
AAB
or Bangalore to 1234 Is creating a Json file on disk a good option for that
Is using sql lite for mapping a value to somehting overkill
 
I mean json is fine if you have a small file, but if it gets to database scale then you should be using something else
 
AAB
I dont think we will have ore 1,00,000 entries ever
but I feel sqllite is still better
cause I don't have to worry about a few things
like say when I update json file and something goes wrong and poof the entire file is corrupted
Easy updating of keys
and if 2 processes wanna update sqllite locks tuff by default
 
yeah, 1 mill is probably a little much, especially if you actually want data-integrity
 
AAB
stuff*
@PeterT Thanks a lot :)
 
 
6 hours later…
4:10 PM
towards the end, why do they push_back and pop_back()? why do this?
 
 
4 hours later…
8:37 PM
@Permian The basic idea is pretty simple. You're trying to find numbers that add up to a particular value (out of some given candidates). The basic idea is to start with an empty solution set. Then take the first candidate, put it into the solution set, and recursively try to find a solution for the amount remaining. Then do the same thing starting from the second candidate, and so on for every possible candidate.
 
8:58 PM
@JerryCoffin i get the push_back is adding to solution set. its the pop_back why is it necessary?
 
@Permian Because once you've made an attempt starting from the first number, you want to make an attempt starting from the second (without the first), and so on for each subsequent number.
 
yeah but it only releases the last element
oh.. i think i see now...this is hard code
dont think i could have written it
why do you need the j there? it seems unused
 
@Permian This is where recursion comes into things.
 
@JerryCoffin i cant see it
 
@Permian A particular invocation just tries different numbers in one position, and then uses recursion to try to find other numbers to fill the subsequent positions.
 
9:12 PM
sorry im totally confused
 
10:08 PM
@Permian Okay, ignore recursion for the moment. I want to figure out combinations of numbers to make up a sum. I start with the first candidate number. I subtract that from the target sum, and then try to find some set of numbers to add up to the reduced sum, right?
 
10:37 PM
of course @JerryCoffin
 
@Permian Okay. So once you've tried out combinations starting from the first candidate, you want to try combinations starting from the second candidate, right?
 
yeah
 
@Permian So this is saying: take the first candidate, and try creating a combination of the others from there. Then take out the first candidate, and try again starting from the second candidate, and so on.
 
i just thought that after the second call the backtrack function you want tmp to grow
but then at the end you only release one element
 
11:08 PM
@Permian A particular call adds an element, then does a recursive call to find other elements that go with it, then removes that one element that it added. Each addition that makes tmp grow is done in a recursive call that adds one element, does a recursive call, then removes the one element it added. So, when tmp contains, say, six elements, there was one initial call plus five levels of recursive calls. As each of those recursive calls returns, its going to remove the last element from tmp.
By the time it returns to the top level call, there's only one element left in tmp, but each recursive call has already popped off the one element it added.
 

« first day (1246 days earlier)      last day (1590 days later) »