Fixing segfault. Off-by-one when setting number of dimensions in StreamingSparseFeatures.

* Commit 7e6e7e9 is a fix for #1441 plus some sanity checks
* Commits 4de54fb and 429cf5e are refactorings to reduce code duplication.
* Commit 8178202 fixes wrong broken unit test and some debug output.