MᏫᎻᎯᎷᎷᎬᎠ
dtor{ if(ptr) {delete ptr;} }
S.
Liam
Just aware of that ... your alignment here is pure OCD style 😂 your employees must feel painful
BTW, if the source array is a circle, i.e. subarraies could go through the end and the begin of the array but not overlap. How to solve the maxSumOFSubarray problem in O(n) time and O(1) space?
S.
We only need to check if overlapped
S.
Why? Consider you extend the n length array into 2n
Liam
Using cellphone... I guess remembering the beginning point of the max sum subarray could be enough?
there are n possible begining points. For every begining point, it's a maxSumOFSubarray problem, hence O(n * n).
S.
Oh I didn’t mean that ... I meant based on the previous greedy solution, adding a beginning point could help check if overlapped, which may be equivalent to using a maxSumSubarrayLength and a flag to check if rewinded...
S.
will have a try when getting back to pc 😅
Ohama |
Hello. i have qouestion about kernel linux. What is kernel book-keeping?
Ибраги́м
Thanks for the help man
Hi, were you able to complete it ?
BinaryByter
most if clauses dont need an else
BinaryByter
+ branching can lead to perf losses
Liam
+ branching can lead to perf losses
No. Your compiler will optimize empty branches out.
MᏫᎻᎯᎷᎷᎬᎠ
btw how can we assign a function pointer to a functor(function object)?
MᏫᎻᎯᎷᎷᎬᎠ
like struct Obj{ void operator()(){ std::cout «"heeey it's me lunatic\n"; } }; then we have : void(*f)() how can we assign Obj.operator() to the above pointer
BinaryByter
No. Your compiler will optimize empty branches out.
Dont make your compilers job harder than it alreafy is
MᏫᎻᎯᎷᎷᎬᎠ
MᏫᎻᎯᎷᎷᎬᎠ
?
MᏫᎻᎯᎷᎷᎬᎠ
cuz I tried it but it's not working
MᏫᎻᎯᎷᎷᎬᎠ
so If I make it static function i can do:
MᏫᎻᎯᎷᎷᎬᎠ
f = void(Obj::* f)(Obj*)
MᏫᎻᎯᎷᎷᎬᎠ
right?
MᏫᎻᎯᎷᎷᎬᎠ
let's see
MᏫᎻᎯᎷᎷᎬᎠ
i forgot
MᏫᎻᎯᎷᎷᎬᎠ
operators can't be static
MᏫᎻᎯᎷᎷᎬᎠ
MᏫᎻᎯᎷᎷᎬᎠ
They are not the same thing.
I once read that lamdas are a functors 🤔
Liam
#include <iostream> struct Foo { void bar(void) { std::cout << "hello world" << std::endl; } }; int main() { Foo foo; void(Foo::* pf)() = &Foo::bar; (foo.*pf)(); return 0; }
Liam
non-static member functions' pointer should be used like this.
MᏫᎻᎯᎷᎷᎬᎠ
hmm
Liam
#include <iostream> struct Foo { void bar(void) { std::cout << "hello world" << std::endl; } static void baz(void) { std::cout << "bye world" << std::endl; } }; int main() { Foo foo; void(Foo::* pbar)() = &Foo::bar; (foo.*pbar)(); void(* pbaz)() = &Foo::baz; pbaz(); return 0; } and for static member functions, they act like normal functions.
MᏫᎻᎯᎷᎷᎬᎠ
the same applies for operator() right?
MᏫᎻᎯᎷᎷᎬᎠ
thanks
MᏫᎻᎯᎷᎷᎬᎠ
okay
Liam
I once read that lamdas are a functors 🤔
This is because: closure type for a lambda-expression with no lambda-capture has a public non-virtual non-explicit const conversion function to pointer to function having the same parameter and return types as the closure type’s function call operator..
MᏫᎻᎯᎷᎷᎬᎠ
xD i'll take a decade to understand that
BinaryByter
I once read that lamdas are a functors 🤔
They are lambdas, the compiler implements them as it wants
BinaryByter
On assembler level, they are probably compiled down to a pointer and a stack for states
MᏫᎻᎯᎷᎷᎬᎠ
They are lambdas, the compiler implements them as it wants
do you know how usually the compiler implements them?
MᏫᎻᎯᎷᎷᎬᎠ
.
lmao it's assembly shit
MᏫᎻᎯᎷᎷᎬᎠ
alright
MᏫᎻᎯᎷᎷᎬᎠ
thank you guys
BinaryByter
Sure
BinaryByter
Calling a function always has overhead over inlining code
BinaryByter
until you get cache misses
BinaryByter
This "zero overhead" thing is a myth
BinaryByter
we should call it "optimal overhead"
MᏫᎻᎯᎷᎷᎬᎠ
Liam
You didn't understand the words. The term overhead here means extra overhead on C++'s abstraction,.
Liam
Function calling's overhead is not brought by C++'s abstraction.
BinaryByter
like the best case?
yes. Like using vars on the stack unlike C# which puts every single fucking one of them onto the heap
Liam
lol
MᏫᎻᎯᎷᎷᎬᎠ
Liam
There are so many concepts in C++ mihgt mislead newbies.
BinaryByter
BinaryByter
There are so many concepts in C++ mihgt mislead newbies.
We should avoid adding more misleading by using bad lingo
MᏫᎻᎯᎷᎷᎬᎠ
C#does that and is 25% slower
wait a minute user-defined types or primitive?