Live data from Hacker News

Ask HN: What are some cool but obscure data structures you know about?

news.ycombinator.com

761–770 of 772 posts

Re: Ask HN: What are some cool but obscure data structures you know about?

#761
post #4

The Israeli queue. Like a regular queue, but if something new that comes in sees its friend in the queue already, it can jump the queue and go and stand next to her. Useful for when something has a big overhead on top of its own processing, but the overhead can be shared between several similar entries. If you're doing it anyway for the one already in the queue, you get to make the most of it for its friends too. I c…

Reminds me a little bit of a "delta queue" used in efficient discrete time based scheduling, for example, in an OS scheduler. Imagine you want to implement a scheduler that accepts jobs and runs them at some point in the future. Instead of keeping a list and scanning through the list at each clock tick, implement a linked list with (time delta, job) at each node. Now, handling a tick() simply requires decrementing the head node and popping items until you see a non-zero delta. Inserting is done like a normal list, except as you iterate through the list, you decrement the desired time interval as you see deltas in the list. It goes like this:

insert(job1, 1) # (job1, 1) -> null insert(job2, 1) # (job1, 1) -> (job2, 0) -> null insert(job3, 2) # (job1, 1) -> (job2, 0) -> (job3, 1) -> null tick() -> job1, job2 # (job3, 0) -> null tick -> job3 # -> null

Re: Ask HN: What are some cool but obscure data structures you know about?

#762
post #534
post #383

Earlier quoted context omitted.

> Much better advice is found in The Practice of Programming: almost all programs can be written without any data structures but arrays, hash tables, linked lists, and, for things like parsing, symbolic algebra, or filesystems, trees. So just use those if you can. In general, as much as possible use stuff you already have good libraries for. Often, you can get away with much simpler data structures with a bit of clev…

Those are good tips. I'm not that enthusiastic about libraries. Yes, using a good LSM-tree library will keep you and your successors from spending holiday weekends debugging your LSM-tree implementation — probably, because "good" doesn't mean "perfect". But it won't be a tenth as fast as an in-RAM hash table, if an in-RAM hash table can do the job. And CPython's standard hash table usually won't be a tenth as fast as…

I like Hypothesis just as much as the next guy. It's awesome.

You have some valid points, when you have specialised needs, you might need to write specialised software.

Though even for your example, I would suggest you write your domain-specific hash table as if it was a library, if possible, (instead of embedding it deep in your application code). Trying to make your code testable with hypothesis strongly encourages such an approach anyway.

(To show that my advice ain't trivial, I give a counterexample where you can't do this as easily: C folks sometimes write things like intrusive linked lists, or intrusive data structures in general. Almost no language gives you good tools to write these as a library, so testing properties in isolation is hard to do, too.)

Re: Ask HN: What are some cool but obscure data structures you know about?

#763
post #762
post #534

Earlier quoted context omitted.

Those are good tips. I'm not that enthusiastic about libraries. Yes, using a good LSM-tree library will keep you and your successors from spending holiday weekends debugging your LSM-tree implementation — probably, because "good" doesn't mean "perfect". But it won't be a tenth as fast as an in-RAM hash table, if an in-RAM hash table can do the job. And CPython's standard hash table usually won't be a tenth as fast as…

I like Hypothesis just as much as the next guy. It's awesome. You have some valid points, when you have specialised needs, you might need to write specialised software. Though even for your example, I would suggest you write your domain-specific hash table as if it was a library, if possible, (instead of embedding it deep in your application code). Trying to make your code testable with hypothesis strongly encourages…

I agree!

Re: Ask HN: What are some cool but obscure data structures you know about?

#764

Not a very deep CS-y one, but still one of my favourite data structures: Promise Maps. It only works in languages where promises/futures/tasks are a first-class citizen. Eg JavaScript. When caching the result of an expensive computation or a network call, don't actually cache the result, but cache the promise that awaits the result. Ie don't make a Map but a Map > This way, if a new, uncached key gets requested twice…

[deleted]

Re: Ask HN: What are some cool but obscure data structures you know about?

#767

Input, Output Unionnions. basically a input struct into a algorith, layed out in such a way, that the algorithms output, always only overwrites input no longer needed. If done well, this allows for hot-loops that basically go over one array for read & write-backs. After all, its all just memory and to use what you got in situ is the fastet way one can go. No pointers to dereference and wait, just the input, computate…

Do you have any references for this? I'd like to understand better

https://hackaday.com/2018/03/02/unionize-your-variables-an-i...

https://en.wikipedia.org/wiki/Test-driven_development

This is unsafe C Code by nature, but test driven development on platform can make it "safe".

Now you start with a struct in the union: {inputA, inputB, inputC}

and pad the intermediate struct

{Padding against Overlap, resultB, result C}

and end up with the result struct in the same union.

{outputA, outputB, outputC} .

The trick is to keep track of the state and validate the "purity" via automated tests.

Then you have it all in one L1 Cache Line, pumping through a algo, no dereferences, no huge stack structures, its all there, as long sas the size of input output does not differ wildly.

Remember down there its all just bytes accessed by code. There is no such concept as objects or even variables. All those mental pots to grab things out and put things back in, are artificial constructs needed by us.

The machine down there, can go to work like a line cooking shiva in a trailer. And doing so and having this in view, makes it faster.

PS: Pointers within the struct nullifys the advantages gained here, because every pointer is a memory load and thus "relatively" slow.

Re: Ask HN: What are some cool but obscure data structures you know about?

#768

Some ones I've used recently: The "golden section search" to find a the minimum (or maximum) of a unimodal function. An actual real-world use case for the golden ratio. Exponentially Weighted Moving Average filters. Or how to have a moving average without saving any data points.. Some of my classic favorites: Skiplists: they are sorted trees, but the algorithms are low complexity which is nice. Boyer-Moore string sea…

This is a great selection. Thanks for sharing.

Re: Ask HN: What are some cool but obscure data structures you know about?

#769
For my final project in college Data Structures I wrote a linked hexagonal data structure. To index it I used two different solutions. One was to use a base-6 system to encode a series of hops in the six different directions. Another was to have two coordinates which indicated how far to traverse in two directions to reach the target hex cell.

Re: Ask HN: What are some cool but obscure data structures you know about?

#770
post #232

Here's one I don't know if I've ever seen documented anywhere. If anyone knows a proper name for this one, let me know! Imagine it's for a text editor, and you want to map Line Numbers to Byte Positions. But then you want to insert a byte somewhere, and you need to add 1 to all your Byte Position values. Instead of actually keeping a big array of Byte Position values, you have a hierarchical array. The convention is…

Ted Nelson named them Enfilades. Guy Steele called them Monoid Cached Trees.

Rodney Bates called his independent invention of them K-Trees.
Post reply on HN