Hacker News new | past | comments | ask | show | jobs | submit login

I know the conventional wisdom is that you can't use an array, because O(n). How big of a file can you insert a character into with an O(1) algorithm before it takes more than one refresh time (16 mS)? From the following test program, the file can be 150 MB of text (MBP 2015). I've never had a source file, even a generated one, this long. So I claim that this wisdom is obsolete.

  #include <stdlib.h>
  #include <string>
  using namespace std;
  
  int main(int argc, char **argv)
  {
    size_t size = (size_t)atol(argv[1]);
    string editor_buffer(size, 'x');
  
    for (int iter=0; iter<100; iter++) {
      editor_buffer.insert(5, "foo");
    }
  }



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: