GB2345556A - Device for searching sorted list of data - Google Patents
Device for searching sorted list of data Download PDFInfo
- Publication number
- GB2345556A GB2345556A GB9900123A GB9900123A GB2345556A GB 2345556 A GB2345556 A GB 2345556A GB 9900123 A GB9900123 A GB 9900123A GB 9900123 A GB9900123 A GB 9900123A GB 2345556 A GB2345556 A GB 2345556A
- Authority
- GB
- United Kingdom
- Prior art keywords
- item
- list
- start pointer
- search
- value
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/901—Indexing; Data structures therefor; Storage structures
- G06F16/9024—Graphs; Linked lists
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
A double-linked sorted list has a start pointer, which can be positioned to point to any item in the list. A search mechanism starts at the item currently pointed to by the start pointer, and searches in the direction of increasing or decreasing item values according to whether the search value is less than or greater than the value of the item currently pointed to by the start pointer. The start pointer is repositioned to the last item accessed. This provides reduced search times.
Description
LIST SEARCHING
Background to the Invention
This invention relates to a mechanism for performing fast list searching in a computer.
A list generally consists of a number of data items, chained together by means of pointers. A list may be single-linked, which means that each item has a pointer to the next item in the list only. Alternatively, a list may be double-linked, in which case each item has pointers to both the next and preceding items in the list. Double linking has the advantage that it is easier to remove an item from the list, since both the adjacent items can be immediately located and their pointers adjusted accordingly.
Each list may have a head pointer, which points to the first item on the list. A tail pointer may also be provided, pointing to the last item on the list.
Lists may be unordered, or ordered. In an unordered list, the items are not arranged in any particular order, and new items are added simply by inserting them at the head or tail of the list. In an ordered list, the items are linked together in order of some particular data attribute. In this case, inserting a new item is more difficult, since it is necessary to find the correct place to insert the item.
It is necessary to provide some mechanism for searching a list to find an item having a value that matches a specified search value. Searching such lists can be very time-consuming. The time taken to search a list generally depends on whether the list is unordered or ordered.
In the case of an unordered list, assuming that the position of the searched-for item is random, on average it is necessary to search half the list before the required item is found. In other words, if the time required to examine each item is t, the average search time to locate an item in a list of size N is
T=N*t/2.
To be sure that an unordered list does not contain a particular value, it is necessary to search through every item in the list.
In this case, the time required is F=N*t.
The time taken to insert a new item in an unordered list is unrelated to the size of the list, since the item is simply inserted at the head or tail.
In the case of an ordered list, the average search time T to locate an item in a list of size N is again T=N*t/2. The average time taken to determine that an ordered list does not contain a particular item is F=N*t/2, i. e. it is the same as the search time. The time required to insert a new item equals the time taken to search for the correct place, plus the time i required to insert the item. Thus, in this case the insert time is I=N*t/2 + i.
The object of the present invention is to provide an improved list searching mechanism.
Summary of the Invention
According to the invention, apparatus for storing and retrieving data in a computer comprises: a) a double-linked sorted list: b) a start pointer, movable to point to any item in the list; and c) a search mechanism, for searching for an item having a
specified search value, starting at the item currently pointed
to by the start pointer, the search mechanism searching in the
direction of increasing or decreasing item values according to
whether the search value is less than or greater than the
value of the item currently pointed to by the start pointer.
It can be seen that, if the start pointer is near the middle of the list, on average only one-quarter of the list needs to be searched to find a required item. The average search time is therefore reduced to T=N*tl4. The average time required to determine that the list does not contain an item with a specified value is the same, i. e. F= N*t/4. The average time required to insert a new item is I=N*tl4 + i.
Thus, the present invention represents a significant improvement over conventional list searching mechanisms (with the sole exception that inserting a new item in an unordered list is, of course, faster).
One embodiment of the invention will now be described by way of example with reference to the accompanying drawings.
Brief Description of the Drawings
Figure 1 is a schematic diagram representing a list structure.
Figure 2 is a flow chart showing the operation of a search mechanism for searching the list.
Description of an Embodiment of the Invention
Figure 1 shows a double-linked list 10, comprising a number of data items 11-15. Each item contains a forward pointer, pointing to the next item on the list, and a backward pointer, pointing to the preceding item on the list. At the head of the list 15, the forward pointer has a null value. Similarly, at the tail end 11 of the list, the backward pointer has a null value.
The items on list 10 are linked together in order of increasing values, with the tail item 11 having the smallest value and the head item 15 having the largest value
A movable start pointer 16 can be positioned to point to any item in the list. Initially, it is assumed it is positioned somewhere near the middle of the list. As will be described, each time an item is accessed (inserted or found), the start pointer is repositioned to point to that item.
The list has a search mechanism 17, for searching for an item having a specified search value. Preferably, the search mechanism is implemented in software, running on conventional computer hardware. Alternatively, it could be implemented by special-purpose hardware.
Figure 2 shows the operation of the search mechanism.
(Step 20) The search mechanism first compares the search value with the value of the item currently pointed to by the start pointer 16. If these values are equal, the search mechanism returns"success", indicating that the required item has been found.
(Step 21) If the search value is less than the value of the iter currently pointed to by the start pointer, the search mechanism proceeds to search sequentially down the list, in the direction of decreasing item values, i. e. towards the tail item 11. If the required item is found, the search returns"success". If, however, the tail item 11 is reached without finding the required item the search returns"failure".
(Step 22) If on the other hand the search value is greater than the value of the item currently pointed to by the start pointer, the search mechanism proceeds to search sequentially up the list, in the direction of increasing item values, i. e. towards the head item 15. As before, if the required item is found, the search returns"success". If, however, the head item 15 is reached without finding the required item the search returns "failure".
(Step 23) If the required item is found, the start pointer 16 is repositioned to point to the found item.
The process for inserting a new item is similar to that for searching. If the value of the item to be inserted is less than the value of the item currently pointed to by the start pointer, the list is searched in the direction of decreasing item values, until an item is found with a value less than that of the item to be inserted, or the tail of the list is reached. Conversely, if the value of the item to be inserted is greater than the value of the item currently pointed to by the start pointer, the list is searched in the direction of increasing item values, until an item is found with a value greater than that of the item to be inserted, or the head of the list is reached. In either case, the start pointer is repositioned to point to the newly inserted item.
Repositioning the start pointer to the last item accessed (inserted or found) serves two purposes.
* First, it is a simple expedient, which tends to leave the
start pointer, on average, at the centre of the list. This
helps to minimise search times.
It has the additional benefit that, if a series of adjacent
(or nearly adjacent) items are accessed together, the access
time is further reduced, since items after the first in the
series will be near to the start pointer.
Some possible modifications
It will be appreciated that many modifications may be made to the system described above without departing from the scope of the present invention.
In one possible modification, the list may be configured as a circular list, such that the forward pointer of the head item 15 points to the tail item 11, and the backward pointer of the tail item 11 points to the head item 15. In this case, the search may proceed until either the required item is found, or the search arrives back at the start pointer.
Claims (6)
- CLAIMS 1. Apparatus for storing and retrieving data in a computer comprising: a) a double-linked sorted list: b) a start pointer, movable to point to any item in the list ; and c) a search mechanism, for searching for an item having a specified search value, starting at the item currently pointed to by the start pointer, the search mechanism searching in the direction of increasing or decreasing item values according to whether the search value is less than or greater than the value of the item currently pointed to by the start pointer.
- 2. Apparatus according to Claim 1 including means for repositioning the start pointer to the last item accessed.
- 3. A method for storing and retrieving data in a computer comprising : a) forming a double-linked sorted list: b) providing a start pointer, movable to point to any item in the list; and c) searching for an item having a specified search value, starting at the item currently pointed to by the start pointer, and proceeding in the direction of increasing or decreasing item values according to whether the search value is less than or greater than the value of the item currently pointed to by the start pointer.
- 4. A method according to Claim 3 including repositioning the start pointer to the last item accessed.
- 5. An information carrier, holding a program for implementing a method according to Claim 3 or 4.
- 6. A search mechanism substantially as hereinbefore described with reference to the accompanying drawings.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
GB9900123A GB2345556B (en) | 1999-01-06 | 1999-01-06 | List searching |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
GB9900123A GB2345556B (en) | 1999-01-06 | 1999-01-06 | List searching |
Publications (3)
Publication Number | Publication Date |
---|---|
GB9900123D0 GB9900123D0 (en) | 1999-02-24 |
GB2345556A true GB2345556A (en) | 2000-07-12 |
GB2345556B GB2345556B (en) | 2003-06-04 |
Family
ID=10845561
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
GB9900123A Expired - Lifetime GB2345556B (en) | 1999-01-06 | 1999-01-06 | List searching |
Country Status (1)
Country | Link |
---|---|
GB (1) | GB2345556B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
GB2369465B (en) * | 2000-11-28 | 2003-04-02 | 3Com Corp | A method of sorting and retrieving data files |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
GB1539894A (en) * | 1976-02-18 | 1979-02-07 | Plessey Co Ltd | Data processing apparatus for use in sorting by magnitude |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5333318A (en) * | 1990-09-27 | 1994-07-26 | Motorola, Inc. | Creating and searching a quad linked list in a trunked communication system |
US5263160A (en) * | 1991-01-31 | 1993-11-16 | Digital Equipment Corporation | Augmented doubly-linked list search and management method for a system having data stored in a list of data elements in memory |
CA2100599C (en) * | 1992-07-30 | 2000-10-17 | Praedictus Corporation | Entity-relation database |
US5950191A (en) * | 1997-05-21 | 1999-09-07 | Oracle Corporation | Method and system for accessing an item in a linked list using an auxiliary array |
-
1999
- 1999-01-06 GB GB9900123A patent/GB2345556B/en not_active Expired - Lifetime
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
GB1539894A (en) * | 1976-02-18 | 1979-02-07 | Plessey Co Ltd | Data processing apparatus for use in sorting by magnitude |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
GB2369465B (en) * | 2000-11-28 | 2003-04-02 | 3Com Corp | A method of sorting and retrieving data files |
Also Published As
Publication number | Publication date |
---|---|
GB9900123D0 (en) | 1999-02-24 |
GB2345556B (en) | 2003-06-04 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US4916655A (en) | Method and apparatus for retrieval of a search string | |
US5060143A (en) | System for string searching including parallel comparison of candidate data block-by-block | |
US5412807A (en) | System and method for text searching using an n-ary search tree | |
US7062499B2 (en) | Enhanced multiway radix tree and related methods | |
US5659739A (en) | Skip list data structure enhancements | |
CN110580255A (en) | method and system for storing and retrieving data | |
JP2003224581A (en) | Longest match retrieval circuit, its method, its program, and recording medium | |
GB2345556A (en) | Device for searching sorted list of data | |
JP2865831B2 (en) | Parallel string search device | |
CN109241098B (en) | Query optimization method for distributed database | |
CN111581440B (en) | Hardware acceleration B + tree operation device and method thereof | |
JP2802064B2 (en) | Database processor | |
JP2550022B2 (en) | Document information search method | |
JPH10177582A (en) | Method and device for retrieving longest match | |
JPH04112253A (en) | Data accessing method using multilayer buffer | |
JP2586172B2 (en) | Table search device with learning function | |
JPH0546663A (en) | Key word retrieval system | |
JPH04279973A (en) | Character string comparison system | |
JPH0628399A (en) | Retrieval device | |
JPH0380367A (en) | File managing system | |
JPS6373422A (en) | Information retrieving device | |
JPS63175923A (en) | Sequential organizing file retrieving system | |
JPH05313971A (en) | Key word managing system in relational data base | |
JPH05197755A (en) | Data retrieving system by table development | |
JPH04312170A (en) | System for retrieving japanese character string |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PE20 | Patent expired after termination of 20 years |
Expiry date: 20190105 |