next up previous
Next: Comparing sequence data Up: Sequence Interfaces Previous: The Sequence Abstract

The C Interface

How would this translate into C? First some type definitions:

typedef ReturnCode int; /* 1 for success, zero or negative for failure */
typedef Position int; /* a position in the sequence */
/* the first item in the sequence is at position 0 */
typedef Item unsigned char; /* they are sequences of eight bit bytes */
typedef struct {
/* To be determined */
/* Whatever information we need for the data structures we choose */
} Sequence;

In this interface the only operations that change the Sequence are Insert and Delete.

Many variations are possible. The next few paragraphs discuss some of them.

Any practical interface would allow the sequence to be initialized with the contexts of a file. In theory this is just the Empty operation followed by an Insert operation for each character in the initializing file. Of course, this is too inefficient for a real text editor.gif Instead we would have a NewSequence operation:

Usually the Delete operation will delete any logically contiguous subsequence

Sometimes the Insert operation will insert a subsequence instead of just a single character. Sometimes Copy and Move are separate operations (instead of being composed of Inserts and Deletes). A Replace operation that subsumes Insert and Delete in another possibility. Finally the ItemAt procedure could retrieve a subsequence.

These variations will not affect the basic character of the data structure used to implement the sequence or the comparisons between them that follow. Therefore I will assume the first interface (Empty, Insert, Delete, IntemAt, and Close).


next up previous
Next: Comparing sequence data Up: Sequence Interfaces Previous: The Sequence Abstract

Charlie Crowley
Thu Jun 27 15:36:10 MDT 1996