Use emplace instead of insert whenever possible for set and map.

Fix #309.