From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fe8fca999e54f9fe X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-26 11:12:41 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!upp1.onvoy!onvoy.com!news-out.visi.com!hermes.visi.com!uunet!ash.uu.net!world!news From: Robert A Duff Subject: Re: how to create an array of N elements? Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Mon, 26 Aug 2002 18:11:31 GMT References: <3D5E76C3.1070005@cogeco.ca> <3d63525a_4@news.bluewin.ch> NNTP-Posting-Host: shell01.theworld.com Organization: The World Public Access UNIX, Brookline, MA X-Newsreader: Gnus v5.7/Emacs 20.7 Xref: archiver1.google.com comp.lang.ada:28424 Date: 2002-08-26T18:11:31+00:00 List-Id: "Jonas Gasser" writes: > my editor is finished, but in the moment I use for saving the lines an array > with 1 .. 8000 elements, with or without a string inside -> and I think that > this isn't very convenient. > that's why I'm need a better solution. Here's a reasonable data structure for an editor: Create an array somewhat bigger than the size of the file being edited. Store the characters in that array, with a "hole" in the middle. The hole is the current point of insertion/deletion (where the "cursor" is on the screen). So if the file contains "Hello, world.", the array might contain: Hello, woXXXXXrld. Where "XXXXX" represents the hole. The user is currently editing at the point between "o" and "r". If the user moves the cursor forward one, the array becomes: Hello, worXXXXXld. I.e., copy the "r" to the left of the hole. (I don't mean to imply that the X's are actually stored -- the contents of the hole are irrelevant.) Inserted characters shrink the hole. When the hole disappears, allocate a bigger array. So you really need a pointer-to-array (since the thing can grow and shrink), plus a couple of integers indicating the hole boundaries. Obviously, no such data structure is built in to a general-purpose language like Ada. You need to make it a private type, completed by a record type containing the appropriate stuff, and define operations for insertion, deletion, cursor movement, etc. - Bob