Is there a way to support adding characters in the middle and update the hash in O(1) ? All I have is the hash of ABBDE and I want to get the hash of ABBCDE.
With just the Rolling HASH for the whole ABBDE, you can not insert into the middle of it.
But... as I understand rolling Hash...
If you are building the hashes up as you go (adding into the middle, adding other entries), you would need a little extra information to be able to insert into the middle at a latter access.
As I see it , You need need to know:
A) The whole hash (I assume you got by finding the entry there) B) The hash for one of the halves (Left or Right) C) A length of the HALF to know the offset that needs to be adjusted by. D) An indicator to know which half is being adjusted to keep the halves balanced.`
Then all the parts can be used to recalculate, updated, replaced, and inserted to make new entries.
This would then give an O(1) time
BTW, what is this for?
The answer to another question with a related general solution: Finding Hash of Substring [i, j] in O(1) using O(|S|) pre computation