|
-
May 17th, 2008, 12:53 AM
#11
Re: Best data structure for notepad application
For larger text files, string it not a good solution - for both non-terminated C-style strings or strings which store their length. What if you need to insert some text at the beginning of document (say at 50th character, in a 2MB document). You need to run a loop even for one character insert/delete till 2000000+ counts?
I would recommend using linked list (or std::list), and store each line as list' one element. Each list' element would be 'string' - which you may limit to few KBs. Any replace, insert, delete would be just replacing the string contents for that line. This would, of course, not require whole 'list' object to be traversed.
Now here comes the hard part: when there is line break, or merging of two lines - the two list' elements needs to be merged. Say 6th and 7th lines are merged, you need to append 7th line content into 6th, and delete the 7the line from list. 8th line would now become 7th and so on.
Special taken must be taken care of of multiple lines are being deleted, inserted or replaced - this might be complicated, but appropriate solution.
Similar thing needs to be done where a single line is being breaked into two lines (a simple Enter key would do!).
But if your text-editor would be limited (or you place this limitation) to few KBs, you can straightly use string as data-structure. Remeber Notepad.EXE used to support only 65K files?
Last edited by Ajay Vijay; May 17th, 2008 at 12:55 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|