Added path compression and caching for getBaseDecomposition.