add KMP index method and getNext function