Unusual solutions to avoid a breaking change

In the 1990’s and early 2000’s, I spent a lot of time travelling between London and Yorkshire. Much of that was spent driving on the A1. I recently repeated the journey and was taken aback at the lack of roundabouts (yes, this national 70 mph trunk road was regularly interrupted by roundabouts) and I missed Grantham Services, my usual halfway stop (being on a roundabout, it used to be convenient and hard to miss).

Happily, the services are still there, it’s just that they moved the motorway:

Grantham used to be built on the A1 southbound, with a roundabout to the north allowing northbound traffic to access it and a loop road back to the roundabout allowing them to get back. Recently the Highways Agency brought the A1 to the west of this interchange, with the old road becoming the southbound sliproads and a new bridge being constructed for northbound traffic.

In other related commuter news, London’s Docklands Light Railway recently solved a problem with short platforms by moving the station:

The station was constrained by sharp curves at both ends and could not therefore be further extended on its former site. The DLR’s plans to operate 3 car trains on this line therefore included the relocation of this station some distance to the east.

Incredibly, they built the new station and dismantled the old one without any disruption to the railway!

Leave a comment

Filed under Musing

std::sort now guarantees complexity O(N * log N) under C++11 Standard

I learnt recently that in the C++11 Standard, std::sort is required to have complexity O(N * log N) – not “on average N * log N with a worst case O(n^2)”, but guaranteed O(N * log N). This follows David Musser’s paper on Introspective Sorting and Selection.

Musser’s IntroSort uses QuickSort, but also monitors the number of partitions that have occurred. For example, one might use “median-of-3” to pick each pivot, but that could cause the O(N^2) behaviour if pathological sequence is encountered. In the paper, such a sequence is described by construction. IntroSort switches to HeapSort (which guarantees O(N * log N) performance) once the number of QuickSort partitions reaches 2 * log N. Musser proves that the overall algorithm performance remains O(N * log N).

As pointed out on StackOverflow, std::nth_element could be re-implemented with similar benefits:

Ideally exactly the same should apply std::nth_element but the ISO C++ 2011 standard has not tightened up the complexity requirements. So std::nth_element could be O(N * N) in the worst case.

Leave a comment

Filed under C++, Programming

Why call std::move on a variable that is already T&&?

A StackOverflow question asks why it is necessary to call std::move on a parameter when implementing a move constructor, given that the parameter is already declared T&&?

Named rvalue references are lvalues. Unnamed rvalue references are rvalues.

In other words, if you don’t explicitly move a into b X b = std::move(a); then you haven’t declared that you’ve finished with a, which is a named variable – so the compiler will call X’s copy constructor instead of X’s move constructor.

Leave a comment

Filed under C++, Programming

“Contextually converted to bool”

Chris Sharpe blogged an example of how marking operator bool() explicit neededn’t necessitate any overhead when using that type in a simple if condition:

An expression e can be implicitly converted to a type T if and only if the declaration T t=e; is well-formed, for some invented temporary variable t (8.5). Certain language constructs require that an expression be converted to a Boolean value. An expression e appearing in such a context is said to be contextually converted to bool and is well-formed if and only if the declaration bool t(e); is well-formed, for some invented temporary variable t (8.5). The effect of either implicit conversion is the same as performing the declaration and initialization and then using the temporary variable as the result of the conversion.

Leave a comment

Filed under C++, Programming

Intelligent machines making their own decisions

Interesting article on LinkedIn about intelligent machines collaborating and communicating together to make decisions.

For example, sensors on your roof could sense that it’s a sunny day. The roof sensor is connected to the thermostat, and based on the data the thermostat receives, it automatically adjusts the inside temperature on the sunny side of the house and lowers the automatic shades before you do.

Imagine having all of the airplanes flying over every country wirelessly communicating to each other—not to all of the pilots, but the planes themselves communicating to each other real time flying conditions such as temperature, humidity, wind direction, speed, and turbulence. Each plane can then better anticipate potential issues and help the pilots respond before there is a problem.

Leave a comment

Filed under Technology

Optimizing C++ code (Visual C++ Team blog)

The Visual C++ Team blog has started a series on Optimizing C++ code.

  1. Introduction
  2. Overview
  3. Constant Folding
  4. Dead Code Elimination

Leave a comment

Filed under C++, Programming

Universal memorisation for C++

ISOCpp linked to a StackOverflow question about universal memorisation.

Leave a comment

Filed under C++, Programming

Regulators crack down on HFT market spoofing algos

Finextra reports that regulators have begun to crack down on HFT firms that employ algorithms to submit fake orders to manipulate the market.

Regulators on both sides of the Atlantic have levelled their first fines against high frequency traders who deployed computer algorithms to spoof the markets by placing and immediately cancelling bids and offers in futures contracts.

David Meister, the CFTC’s enforcement director, says: “While forms of algorithmic trading are of course lawful, using a computer program that is written to spoof the market is illegal and will not be tolerated. We will use the Dodd Frank anti-disruptive practices provision against schemes like this one to protect market participants and promote market integrity, particularly in the growing world of electronic trading platforms.”

Leave a comment

Filed under Finance

Book Review: Night Fall, Nelson DeMille

NightFallThis is another John Corey novel by Nelson DeMille. What I admire about DeMille is that he’s written a couple of brilliant, one-off books set during the Cold War (The Charm School, The Talbot Odyssey) as well as this modern day series about a semi-retired NYPD detective with a sharp, though politically incorrect, sense of humour. This title has many of the signature John Corey features: struggle against the reach and might of the FBI/CIA; grapple with mortal enemy Ted Nash; call on NYPD contacts for off-the-books investigations; act like a jerk but still win the heart of the lovely Kate Mayfield. But it’s also based on a true story, the crash of flight TWA 800, and DeMille handles that with sensitivity whilst telling his own fictional story alongside the true horror of the crash.Four starts

1 Comment

Filed under Book Review

XPerf Trace Viewer

Bruce Dawson wrote a review of xperf and Windows Performance Analyzer.

Leave a comment

Filed under Programming