AB=AAA...ABBB...B
if the entity is of type B:
IndexInAB = AmountOfA + AmountOfBEntitiesBeforeEntity + 1 //i think
if its A:
IndexInAB = AmountOfAEntitiesBeforeEntity + 1
This is assuming that you add the A/B in the AB container each time you add a new entity, always at the end of all As or Bs, and that the entity you add will be the highest ID and that there are no gaps in the entity ID's
But if you are going for something dynamic your system isnt really going to work. It might work for some serialization but for other things not so well.