0

CollaborativeString.setText: Sets the contents of this collaborative string. Note that this method performs a text diff between the current string contents and the new contents so that the string will be modified using the minimum number of text inserts and deletes possible to change the current contents to the newly-specified contents.

This is a minor point but the documentation is technically inaccurate. The minimum number of edits to change one string to another is always at most 2: delete the whole string and insert the new string.

For example, to change, to change baaaaaaaab to caaaaaaaac, the realtime api does the sensible thing which is to use a delete event for each b and a corresponding insert event for each c.

Out of curiosity, can the exact text diff algorithm for this be made public? I have tried several diff algorithms which haven't reproduced the exact algorithm.

Christopher Best
  • 466
  • 4
  • 14

1 Answers1

1

I guess the documentation isn't totally clear, but its the min number of inserts and deletes to get to the end state without restating things that stayed the same.

I doubt we'd want to state anything more specific about the algorithm, since its subject to change without notice :) Why do you care?

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
  • To reproduce it in a library that implements the realtime api in local documents or documents stored elsewhere. https://github.com/sirctseb/realtime-data-model-js – Christopher Best Mar 25 '15 at 19:23
  • You can now use the realtime API in "in memory mode", which may solve that use case? Its not fully documented yet, but available in the API. See http://stackoverflow.com/questions/28097320/google-realtime-undocumented-feature-tojson – Cheryl Simon Mar 25 '15 at 19:29
  • I'm excited about that feature (so I don't have to maintain my own implementation), but does it still require the user to be authenticated? If so it is much less valuable – Christopher Best Mar 25 '15 at 19:31
  • 1
    Sold! 10 more characters – Christopher Best Mar 25 '15 at 19:32
  • If you still end up wanting your own implementation or server code, you should take a peek at https://github.com/goodow/realtime. – Grant Watters Mar 25 '15 at 22:43