Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The inverse is also true, often you have linear or even quadratic lookup times when something like an index can give you the result "immediately".

I wish languages other than SQL had a concept of adding an index. Imagine a variant of Python's list or C++'s vector where you can add indicies on arbitrary fields of the contents, like a more flexible dict. Something like (pseudocode)

    books = List<Book, indices=[Book.title, Book.author]>
and then you could up by title or author without traversing the whole list. Sure you can just use a separate dict, but then you have to keep both in sync, it is harder to bind it to UI controls, and so on.


In my experience these type of abstractions end up bloated with too many concerns which adds maintenance overhead. It's a lot simpler to simply add a `HashMap<Book.title, Book>` and cover with tests, than use an abstraction.

I want languages to do less magic, not more, since I read code more than I write it.


For C++ there's Boost's multi_index[1].

[1]: https://www.boost.org/doc/libs/1_82_0/libs/multi_index/doc/i...


I used multi_index a lot in the past. However, since I also frequently use sqlite, I have decided to exclusively use SQLite for multi_index in memory. If there is a problem, temporarily using sqlite as a file makes it a lot easier to track the issue. When multi_index patterns become too complex, it's natural to wrap them in a unit test specifically designed for sqlite (multi_index).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: