Live data from Hacker News

Write a hash table in C

github.com

51–58 of 58 posts

Re: Write a hash table in C

#51
post #34

I've heard of two possibilities (as a recommendation) for using data structures in C without having to develop them: - BSD queue.h offers linked lists, queues, etc [1]. - UT-hash offers hash tables [2]. I've also read some people being frustrated with them, probably due to the quirky syntax/API. On the plus side (BSD at least) it's just a header file that you can download, include and start using. [1] http://bxr.su/O…

Have a look for Phong Vo's CDT - container data type - library.

Re: Write a hash table in C

#52
post #50
post #42

Earlier quoted context omitted.

A standards process is frequently about documenting what already exists in common implementations so that there is a specification for future implementations. POSIX was very much one of these processes.

OK... so how did junk like this ever get into enough implementations that people were forced to include it in the standard? ;)

tsearch/hsearch/lsearch have been around for at least 30 years. My guess is that they've been around for a lot longer.

Why not have these anyway? Otherwise people will make their own (probably buggy) equivalents.

I'm actually surprised that people aren't aware of them.

Re: Write a hash table in C

#53
post #5

While the reasons for this that the author gave are valid, I think it would also be valuable to do this in a high level language. I'm sure lot of people who can read C code went through a CS program, and hopefully learned how hash tables work then. People without CS degrees and who mostly write JS/Ruby/Python/etc. and use hash tables on almost every line of code they write are much less likely to know how they work.…

You could always port it.

Re: Write a hash table in C

#54
post #34

I've heard of two possibilities (as a recommendation) for using data structures in C without having to develop them: - BSD queue.h offers linked lists, queues, etc [1]. - UT-hash offers hash tables [2]. I've also read some people being frustrated with them, probably due to the quirky syntax/API. On the plus side (BSD at least) it's just a header file that you can download, include and start using. [1] http://bxr.su/O…

A bit of ongoing work from me. Trying to make wiring C programs fast and painless.

https://github.com/mgrosvenor/libchaste

Re: Write a hash table in C

#55

Earlier quoted context omitted.

> There's room for both. Sure. I'm all for learning ML, Scheme, C/C++, Python, Ruby, Java/C#, etc. > There's a reason why a lot of CS programs have shuffled from primarily C to Python (some had Java in between). The reason is called dumbing down the curriculum. My fall freshman year, my college tried to switch from C to Java in order to make it easier for the general population to get into CS and there was a major pu…

The dumbing down of the curriculum so that music/english majors can pass CS classes doesn't do anyone any favors. You sound butt-hurt

We ban accounts that post like this, so would you please not?

https://news.ycombinator.com/newsguidelines.html

Re: Write a hash table in C

#56
post #16

Earlier quoted context omitted.

There's room for both. There's a reason why a lot of CS programs have shuffled from primarily C to Python (some had Java in between). Not having to deal with boilerplate and housekeeping lets you focus on learning the topic at hand. Especially in a classroom setting where you're probably focusing on the specific subject instead of real-world dirtiness. But after learning the basic concept, you do need an actual imple…

> There's room for both. Sure. I'm all for learning ML, Scheme, C/C++, Python, Ruby, Java/C#, etc. > There's a reason why a lot of CS programs have shuffled from primarily C to Python (some had Java in between). The reason is called dumbing down the curriculum. My fall freshman year, my college tried to switch from C to Java in order to make it easier for the general population to get into CS and there was a major pu…

> so that music/english majors can pass CS classes

This breaks the HN guideline against flamebait. Please don't post like this here.

https://news.ycombinator.com/newsguidelines.html

Re: Write a hash table in C

#57
post #50

Earlier quoted context omitted.

OK... so how did junk like this ever get into enough implementations that people were forced to include it in the standard? ;)

tsearch/hsearch/lsearch have been around for at least 30 years. My guess is that they've been around for a lot longer. Why not have these anyway? Otherwise people will make their own (probably buggy) equivalents. I'm actually surprised that people aren't aware of them.

This is specifically about hcreate/hsearch, which are utterly useless, since you only get one hash table at a time. The reason you don't want crap like this is just that: it's crap.

The _r versions look perfectly sensible.

Re: Write a hash table in C

#58
post #56

Earlier quoted context omitted.

> There's room for both. Sure. I'm all for learning ML, Scheme, C/C++, Python, Ruby, Java/C#, etc. > There's a reason why a lot of CS programs have shuffled from primarily C to Python (some had Java in between). The reason is called dumbing down the curriculum. My fall freshman year, my college tried to switch from C to Java in order to make it easier for the general population to get into CS and there was a major pu…

> so that music/english majors can pass CS classes This breaks the HN guideline against flamebait. Please don't post like this here. https://news.ycombinator.com/newsguidelines.html

It isn't flame bait. It was the reason our Dean gave for switching from C to Java. The thinking was that the learning curve for C was too high and the Math/Computer Science wanted to attract more humanities majors to take CS classes.

Introduction to Programming became a requirement and the drop-out/failure rate for non-CS major students was excessively high so the Dean thought teaching the classes in java rather than c would help out those who were new to programming and help them pass these "newly required" classes.

Post reply on HN