frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

C++: Maps on Chains

http://bannalia.blogspot.com/2025/07/maps-on-chains.html
29•signa11•2d ago

Comments

gsliepen•6h ago
It's a somewhat interesting article, but it doesn't say much. It starts with:

> Suppose we want to have a C++ map where the keys are disjoint

And then we do something that goes against the whole point of such a map:

> But what happens if we try to insert an interval which is not disjoint with those already in the map?

And the solution is:

> Implementation-wise, we just have to [throw an exception if we are] comparing partially overlapping intervals

Much more interesting would be to show how to implement a proper interval map.

Gupie•6h ago
Why can't you use this for the comparison operator:

  bool operator<(const interval& x, const interval& y)
  {
     if x.min < y.min return true;
     if x.min > y.min return false;
     return x_max < y.max;
   }
mgaunard•4h ago
better implemented as

    tie(x.min, x.max) < tie(y.min, y.max)
gsliepen•2h ago
Or since C++20, just default operator<=>: https://en.cppreference.com/w/cpp/language/default_compariso...
Sharlin•31m ago
That’s fine if you just need any well-defined SWO, but I presume the author needs this specific ordering for some algorithmic reason. Still, it’s pretty ugly for a comparator to be throwing.
z_open•6h ago
Throwing a runtime error seems like an absurd solution compared to changing the comparison operator or using an unordered_map

What's wrong with x.min < y.min || (x. min == y.min && x.max < y. max)

gsliepen•5h ago
That would indeed satisfy std::map, but then the question is, is that a useful ordering for intervals? To answer that, you need to define what you want to use the interval map for. If you want to be able to lookup in which unique interval a given value is, then you shouldn't have overlapping intervals to begin with. If you do allow overlapping intervals, a query could result in multiple intervals. Are lookups by value (not by interval) still O(log N) with that ordering?
monkeyelite•21m ago
He’s just asserting he’s using the data structure in the way he wants to.
derriz•3h ago
I don’t understand the point of this article. There is no requirement stated regarding the properties of the ordering - in fact there is no code at all that depends on the traversing the map elements in a particular order. So you can pick any ordering you want.

If the requirement is “use std::map to store items but prevent adding items to the map if they have a particular relationship to existing map keys”, then this is a terrible solution - std::map like maps and dictionaries in all programming language is not designed for this - it should never be an error to add a value associated with a key to a map instance. Hacking the ordering to implement a requirement like this is brittle, obscure and strange.

If this were proposed as a solution to the problem “design a data structure to store values keyed by intervals that prevents overlapping intervals”, then I would mark it very low.

dm270•1h ago
I agree. This seems very unintuitive and would be a code smell in a review.
monkeyelite•15m ago
> then I would mark it very low.

What would you do differently? I would also assert if any overlapping intervals were inserted - it’s an invariant of his data structure.

If it was static I would just sort and binary search, but if not this seems like a fine way to reuse the std::map.

These templates are designed for this kind of thing - make a custom comparator, document why it works, wrap it in a typedef.

diath•47m ago
This had bit me in the past with std::sort that made seemingly benign code randomly crash a live service, cppreference has a list of all the standard facilities that need to meet these requirements: https://en.cppreference.com/w/cpp/named_req/Compare.html

Gaming Cancer: How Citizen Science Games Could Help Cure Disease

https://thereader.mitpress.mit.edu/how-citizen-science-games-could-help-cure-disease/
48•pseudolus•3h ago•20 comments

Let Me Pay for Firefox

https://discourse.mozilla.org/t/let-me-pay-for-firefox/141297
411•csmantle•5h ago•328 comments

Bypassing Google's big anti-adblock update

https://0x44.xyz/blog/web-request-blocking/
771•deryilz•18h ago•665 comments

The upcoming GPT-3 moment for RL

https://www.mechanize.work/blog/the-upcoming-gpt-3-moment-for-rl/
63•jxmorris12•3d ago•21 comments

Show HN: ArchGW – an intelligent edge and service proxy for agents

5•honorable_coder•14h ago•3 comments

Notes on Graham's ANSI Common Lisp (2024)

https://courses.cs.northwestern.edu/325/readings/graham/graham-notes.html
28•oumua_don17•3d ago•2 comments

Axon's Draft One AI Police Report Generator Is Designed to Defy Transparency

https://www.eff.org/deeplinks/2025/07/axons-draft-one-designed-defy-transparency
52•zdw•2d ago•9 comments

The Decipherment of the Dhofari Script

https://www.science.org/content/article/mysterious-pre-islamic-script-oman-finally-deciphered
19•pseudolus•3h ago•5 comments

Understanding Tool Calling in LLMs – Step-by-Step with REST and Spring AI

https://muthuishere.medium.com/understanding-tool-function-calling-in-llms-step-by-step-examples-in-rest-and-spring-ai-2149ecd6b18b
17•muthuishere•4h ago•0 comments

Zig's New Async I/O

https://kristoff.it/blog/zig-new-async-io/
245•afirium•15h ago•190 comments

Chrome's hidden X-Browser-Validation header reverse engineered

https://github.com/dsekz/chrome-x-browser-validation-header
254•dsekz•2d ago•71 comments

The North Korean fake IT worker problem is ubiquitous

https://www.theregister.com/2025/07/13/fake_it_worker_problem/
26•rntn•1h ago•9 comments

Aeron: Efficient reliable UDP unicast, UDP multicast, and IPC message transport

https://github.com/aeron-io/aeron
50•todsacerdoti•17h ago•21 comments

Hacking Coroutines into C

https://wiomoc.de/misc/posts/hacking_coroutines_into_c.html
114•jmillikin•12h ago•30 comments

Parse, Don’t Validate – Some C Safety Tips

https://www.lelanthran.com/chap13/content.html
85•lelanthran•4d ago•39 comments

C++: Maps on Chains

http://bannalia.blogspot.com/2025/07/maps-on-chains.html
29•signa11•2d ago•12 comments

Switching to Claude Code and VSCode Inside Docker

https://timsh.org/claude-inside-docker/
184•timsh•1d ago•109 comments

Lua beats MicroPython for serious embedded devs

https://www.embedded.com/why-lua-beats-micropython-for-serious-embedded-devs
14•willhschmid•5h ago•4 comments

Monitoring My Homelab, Simply

https://b.tuxes.uk/simple-homelab-monitoring.html
14•Bogdanp•3d ago•1 comments

Experimental imperative-style music sequence generator engine

https://github.com/renoise/pattrns
34•bwidlar•4d ago•5 comments

Capturing the International Space Station (2022)

https://cosmicbackground.io/blogs/learn-about-how-these-are-captured/capturing-the-international-space-station
23•LorenDB•3d ago•2 comments

Edward Burtynsky's monumental chronicle of the human impact on the planet

https://www.newyorker.com/culture/photo-booth/earths-poet-of-scale
64•pseudolus•11h ago•9 comments

Lost Chapter of Automate the Boring Stuff: Audio, Video, and Webcams in Python

https://inventwithpython.com/blog/lost-av-chapter.html
176•AlSweigart•21h ago•11 comments

MacPaint Art from the Mid-80s Still Looks Great Today

https://blog.decryption.net.au/posts/macpaint.html
932•decryption•1d ago•185 comments

Kimi K2 is a state-of-the-art mixture-of-experts (MoE) language model

https://twitter.com/Kimi_Moonshot/status/1943687594560332025
238•c4pt0r•1d ago•147 comments

The fish kick may be the fastest subsurface swim stroke yet (2015)

https://nautil.us/is-this-new-swim-stroke-the-fastest-yet-235511/
231•bookofjoe•1d ago•158 comments

Two-step system makes plastic from carbon dioxide, water and electricity

https://phys.org/news/2025-06-plastic-carbon-dioxide-electricity.html
72•PaulHoule•3d ago•30 comments

HNSW as abstract data structure: video intro to Redis vector sets [video]

https://www.youtube.com/watch?v=kVApsFUeuEA
41•antirez•3d ago•0 comments

Reading Neuromancer for the first time in 2025

https://mbh4h.substack.com/p/neuromancer-2025-review-william-gibson
110•keiferski•6h ago•111 comments

New Date("wtf") – How well do you know JavaScript's Date class?

https://jsdate.wtf
360•OuterVale•1d ago•209 comments