Substantially speed up sparsity building

Use a boost flat_set instead of an STL set when building the sparsity
pattern, which gives a speedup of about a factor 4.