Moved BaseIndex encode function in-place