Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on a text editor in javascript. I have created the front end and i need to prototype a backend. I need to model the structure of the document using this as hierarchy:

Character , Word , Tag , Document

I am trying to create objects based on this hierarchy.

For example:

Characters are represented a linked list. Word are pointers to the first and last characters. Tags are another linked list of words, and a document is a collection of words and tags.

I am was wondering if anyone has a better suggestion to model these relationships as classes. I receive a character from the keyboard and i need to store this as an object in my document model.


share|improve this question
Could you reword this to identify the problem that you are having editing characters? It would help it fit into the SE format better than asking for various suggestions (which may be equally correct, but not actually fix your problem). – user40980 Feb 15 '13 at 17:49
A linked list of characters, for a text editor?!? That easily makes the document take five times as much space as necessary! Nine times on 64 bit machines. Not to mention that many operations will become severely less efficient due to your code going crazy hopping all over memory. Why do you think you need a linked list? – delnan Feb 15 '13 at 17:51
i need to apply styles to characters such as bold and italic. So i thought using individual character objects would be easier to implement than storing words. – Vinoth Sabanadesan Feb 15 '13 at 18:15
I don't understand the diference between your char and word objects. If you need particular formatting for a char, why not specify it on the word object? The char object should be a char, not a linked list. Will you have a linked list of blanks between each word? – gbianchi Feb 15 '13 at 18:27
I would point out that the fair chunk of the Design Patterns is dealing with a word processor and the patterns to make it fit together. – user40980 Feb 15 '13 at 18:50

You'll want to take a look at Data Structures for Text Sequences, by Charles Crowley.

These 5 notes: 1, 2, 3, 4, 5, have a lot of information on Old School text editor data structures. They may interest you for a number of reasons. First, performance was limited when those were written, so they may end up as very high speed structures today. Second, programs were a lot harder to write, so the very simplicity may appeal to you if you're just trying to get a working back end.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.