← Home ← Back to /g/

Thread 106393856

32 posts 10 images /g/
Anonymous No.106393856 >>106393882 >>106393897 >>106393974 >>106394006 >>106394105 >>106394148 >>106394201 >>106394363 >>106394441 >>106398214
C sisters.... Our response?
Hard mode: Without sounding mad.
Anonymous No.106393882
>>106393856 (OP)
hcreate(3)
Anonymous No.106393897 >>106393974
>>106393856 (OP)
kek
Anonymous No.106393908 >>106394067 >>106394148 >>106395659
You can implement a basic hashmap in C. The hardest part is implementing a decent hash function. Hash functions look like
uint32_t hash(uint32_t x) {
x = ((x >> 16) ^ x) * 0x45d9f3bu;
x = ((x >> 16) ^ x) * 0x45d9f3bu;
x = (x >> 16) ^ x;
return x;
}

And nobody is going to have that shit memorized, so instead you just code a basic hash function (mod the input by some random prime number) and store shit in buckets using linear probing. The speed will be fast enough for any toy problem they're going to give you. A basic hashmap with linear probing is like < 99 sloc. If you can't do this you don't deserve the job.
Anonymous No.106393974 >>106395269
>>106393897
>>106393856 (OP)
>our response
why does the rust tranny child molester keep posting the same cringe thread all the time? it's like the apple spammer.
>get btfo
>rage
>create another thread expecting different result
>rage again
>still gets shit on
embarrassing
Anonymous No.106394006 >>106394047 >>106394189
>>106393856 (OP)
how would rust have helped in this situation when it still requires the same logic?
Anonymous No.106394047 >>106394154
>>106394006
isn't it obvious?

use std::collections::HashMap;
let mut x: HashMap = HashMap::default();
*x.entry(1).or_insert(2) // 2
Anonymous No.106394067 >>106394289 >>106396782
>>106393908
or you can admit that in the year of our lord 2025, even when Golang has done it, that generic programming is non-optional and C has disgustingly fallen behind.
Anonymous No.106394105
>>106393856 (OP)

>simp says is proficient with C because he's based and redpilled

>interviewer laughs, challenges simp, drops mic

Chad interviewer is chad.
Anonymous No.106394148
>>106393856 (OP)
>>106393908
C sisters... not like this...
Anonymous No.106394154
>>106394047
yeah i'm retarded and read it as implementing a hashmap
Anonymous No.106394189
>>106394006
Yes, but unlike Rust, you don't waste time reinventing a hashtable with a trash hashing function.
Anonymous No.106394201
>>106393856 (OP)
>rust
> use std::collections::HashMap
> realize interviewer selected a problem, that's incompatible with the "safe" default
> ask for wifi
> No, but you can use this whiteboard
should have learnt c++
Anonymous No.106394240
Anyone that knows C also knows a subset of C++.
Unless you're mentally ill, in which case you wouldn't get the job even if you pass the interview.
Anonymous No.106394262
hcreate_r, glib, ...
I usually use stb_ds, it's just one header you can download from github.
Anonymous No.106394289
>>106394067
I'm a C++ dev anon, of course I would just use unordered_map
Anonymous No.106394363
>>106393856 (OP)
Further proof all Cniles on /g/ are just CS50 jeets looking for validation because they learnt malloc() once
Anonymous No.106394441
>>106393856 (OP)
Anonymous No.106394511 >>106394527
Did you know that indians consider C and assembly to be low caste programming?
Anonymous No.106394527 >>106394578
>>106394511
Did you know that the rest of the world thinks all indians are low caste?
Anonymous No.106394544 >>106394573 >>106395477
i mean
struct map {
char** keys;
void* values;
int size = 0;
} hmap;

hmap* alloch_hmap(int initial_size) {
initial_size = min(10, initial_size);
hmap* map = malloc(sizeof(hmap));
map->keys = malloc(sizeof(char*) * initial_size);
map->values = malloc(sizeof(void*) * initial_size);
map->size = 10;
return map;
}

void put(hmap* map, char* key, void* value) {
for(int i = 0; i < map->size; i++) {
if(map->keys[i] == null || str_cmp(map->keys[i], key) == 0) {
map->values[i] = value;
}
}
}

void* get(hmap* map, char* key) {
for(int i = 0; i < map->size; i++) {
if(map->keys[i] == null || str_cmp(map->keys[i], key) == 0) {
return map->values[i];
}
}
return null;
}

its not that hard, and its basic implementation. we could start talking about improvements.
Anonymous No.106394573
>>106394544
yes i realize that map->size initialization should be map->size = initial_size
Anonymous No.106394578
>>106394527
I just thought it was interesting information to share in an anti-C thread. Any time you see apparently unfounded hate for something, it's always a good idea to sniff the air and see if there's a curry scent around.
indians also consider non-indians to be lower than even the lowest caste.
Anonymous No.106395269
>>106393974
This website is full of reddit loving retards. They love replying to repost threads.
Anonymous No.106395477
>>106394544
bro forgot the "hash" in hashmap and made an array with extra steps XDDD
Anonymous No.106395659
>>106393908
It turns out that decent hash functions are conceptually simpler than that, provided you don't want cryptographic strength. There's not many papers on this, and a lot of wrong assumptions because damn few people have put the effort in to really measure what makes a good hash.
But one thing: you can't measure whether a hash is good in a vacuum. You need the code to use it and at least one test corpus.
Anonymous No.106396782 >>106396807 >>106396898
>>106394067
Adding non-hardcoded generics to Go was its biggest mistake and a symbolic kneel to the trannies who took it over after the founders backed off. It is now on it's path to being a slow kitchen sink language with no guiding vision.
Anonymous No.106396807 >>106397792
>>106396782
This quote is why I refuse to use Go on general principle. The arrogance in that quote.
Anonymous No.106396898 >>106397792
>>106396782
Let's say you picked haskell. Then you would have to spend at least a year or more teaching literally everyone that joins haskell. And they wouldn't be able to even read let alone modify the code written by a senior dev. Meanwhile all the code being written by the juniors will have to be looked over by a senior in every team. And every time they write something clever or learn something new, a senior dev might not even know it cause there are a billion things to learn in haskell and they are all phd level math/type theory related.
It'll be a total disaster
Anonymous No.106397792 >>106397801
>>106396807
He's just telling the truth if you replace brilliant with complexity-for-its-sake.
>>106396898
I agree. Haskell is a neat language, but it is overly complex for its own sake. You can make efforts to tame it down by enforcing intermediate variables and disallowing silly stuff like monad transformers, but you are fighting its core vision, being a serious research language.
That's why I was so sad when the Go founders backed off and the trannies added generics. Their focus on practicality and real experience was refreshing.
Anonymous No.106397801
>>106397792
C++ has a lot of footguns but doesn't treat me like a child. It's the only modern language that actually gives me everything I need anymore.
Anonymous No.106398214
>>106393856 (OP)
The response is to stop larping (C and Rust) and learn C++ if you want a job in systems / high performant / low latency software.