use hash map and in memory sort during index generation

use hash map and in memory sort during index generation