JPH052607A - High-speed search method using tree-structured data structure - Google Patents

High-speed search method using tree-structured data structure

Info

Publication number
JPH052607A
JPH052607A JP3154377A JP15437791A JPH052607A JP H052607 A JPH052607 A JP H052607A JP 3154377 A JP3154377 A JP 3154377A JP 15437791 A JP15437791 A JP 15437791A JP H052607 A JPH052607 A JP H052607A
Authority
JP
Japan
Prior art keywords
key
block
node
pointer
data structure
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.)
Pending
Application number
JP3154377A
Other languages
Japanese (ja)
Inventor
Morio Kinoshita
盛夫 木下
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hitachi Software Engineering Co Ltd
Hitachi Ltd
Original Assignee
Hitachi Software Engineering Co Ltd
Hitachi Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Hitachi Software Engineering Co Ltd, Hitachi Ltd filed Critical Hitachi Software Engineering Co Ltd
Priority to JP3154377A priority Critical patent/JPH052607A/en
Publication of JPH052607A publication Critical patent/JPH052607A/en
Pending legal-status Critical Current

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

(57)【要約】 【目的】情報探索時の重複する無駄な比較を行わなくて
良く、且つ情報探索時の比較結果を有効に活用して高速
に情報探索を行えるデータ構造を構築することにより、
情報探索時の性能を向上させる。 【構成】探索を目的としたデータ構造において、データ
を識別するための識別子(キー)を複数登録する場合
に、それぞれのキーを比較しやすい大きさのブロックに
分割する。そして、キーの比較を先頭の方のブロックか
らブロック毎に行い、キーの先頭の方のブロックが等し
く、キーの後ろの方のブロックが異なる場合、等しい部
分のブロックを一つだけ保持し、異なる部分のブロック
を木構造のデータ構造になるようにポインタでつないで
保持する。
(57) [Abstract] [Purpose] By constructing a data structure that does not require redundant and redundant comparisons at the time of information search, and that can effectively utilize the comparison results at the time of information search to perform high-speed information search. ,
Improves performance when searching for information. [Structure] When a plurality of identifiers (keys) for identifying data are registered in a data structure for searching, each key is divided into blocks of a size that facilitates comparison. Then, the key comparison is performed for each block from the first block, and when the first block of the key is the same and the second block of the key is different, only one block of the same part is held and different. The partial blocks are connected by a pointer and held so as to form a tree-structured data structure.

Description

【発明の詳細な説明】Detailed Description of the Invention

【0001】[0001]

【産業上の利用分野】本発明は、データ構造に関し、特
に高速な情報の登録および探索が可能なデータ構造に関
するものである。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a data structure, and more particularly to a data structure capable of registering and searching information at high speed.

【0002】[0002]

【従来の技術】従来より、情報の登録、探索を効率よく
実現するデータ構造として、ハッシングや木構造が用い
られている。ハッシングを用いたデータ構造では、発生
するデータ量の推定値が事前に分かっている場合、良好
な性能を得るデータ構造を作成することができる。しか
し、データ量が予測しにくく、またかなり変動する場
合、木構造の方が好ましいことが知られている。従来の
木構造のデータ構造には、2分木、AVL木、最適木、
B木、2−3木、SBB木等さまざまなものがあるが、
いずれも、木の枝の分かれ目や木の枝の先端(以下、節
点と記す)にキーを完全な形で持っていなければならな
い。非常に多くの場合、情報探索のキーは整数のように
一回の比較で大小の判定ができるものではなく、文字列
のように複数回に分割して比較しなければ大小の判定が
できないものである。しかし、従来の木構造ではポイン
タをたどり新しい節点に来る度にキーを先頭から比較し
直さなければならず、一回の比較で比較しきれないよう
なキーの比較回数の削減については全く考えられていな
い。また従来の木構造では、節点でのキーの比較で得ら
れる情報のうち、大きいか小さいかの二つの情報によっ
て、二つのポインタの中からどのポインタをたどるかを
決定しており、節点でのキーの比較で得られる情報の、
どこまでが等しくどこからが違うかという、より詳しい
情報を利用して、二つ以上のポインタの中から一つのポ
インタを選んでたどる方法については全く考えられてい
ない。
2. Description of the Related Art Conventionally, hashing or a tree structure has been used as a data structure for efficiently implementing information registration and search. In the data structure using hashing, when the estimated value of the amount of generated data is known in advance, it is possible to create a data structure that obtains good performance. However, it is known that the tree structure is preferable when the amount of data is difficult to predict and varies considerably. The conventional tree data structure includes a binary tree, an AVL tree, an optimal tree,
There are various trees such as B tree, 2-3 tree, SBB tree,
In each case, the key must be completely held at the branch of the tree branch or the tip of the tree branch (hereinafter referred to as a node). In many cases, the information search key is not something that can be compared to determine the size by a single comparison like an integer, but a character that cannot be determined if it is divided into multiple times and compared like a character string. Is. However, in the conventional tree structure, each time the pointer is traced and a new node is reached, the keys must be compared again, and it is completely conceivable to reduce the number of key comparisons that cannot be compared in one comparison. Not not. Also, in the conventional tree structure, which of the two pointers is to be traced is determined by two pieces of information, which are larger or smaller, among the information obtained by comparing the keys at the nodes. Of the information obtained by comparing the keys,
There is no idea of how to select and trace one pointer from two or more pointers by using more detailed information on how much is equal and where is different.

【0003】なおこの種の技術として関連するものに
は、たとえばANSI(アメリカン・ナショナル・スタ
ンダード・フォ・インフォメーション・システムズ:A
merican National Standard for information s
ystems)データベース・ランゲージ:database langua
ge−SQL(規格番号X3.135−1986)などが
ある。
[0003] Related to this kind of technology, for example, is ANSI (American National Standard for Information Systems: A).
merican National Standard for information s
ystems) database language: database langua
ge-SQL (standard number X3.135-1986).

【0004】[0004]

【発明が解決しようとする課題】木構造で各節点にそれ
ぞれのキーを完全な形で持つデータ構造では、木構造の
根(root)から目的のキー又はキーの挿入場所を探
すときに、ポインタをたどり目的のキーにたどり着くま
での間の各節点で、その節点にあるキーと探しているキ
ーの比較を行う。キーは通常長いものもあれば短いもの
もある。そのため、節点にあるキーと探しているキーの
比較は一回で行えないものが多く、キーを分割し複数回
に分けて比較し、比較結果(キーの大小)によってどの
ポインタをたどるかを決定する場合がほとんどである。
そのため、キーの先頭の方は同じで後ろの方が違うキー
が複数登録されている場合(多くのキーを登録する場
合、必ずこのような状態が発生する)、これらの節点で
の比較で、毎回キーの先頭の同じ部分の比較をやりなお
さなければならないという問題が生じる。
In a data structure having a key in each node in a tree structure in a complete form, a pointer is used when searching for a target key or a key insertion position from the root of the tree structure. At each node until the desired key is reached, the key at that node is compared with the key you are looking for. Some keys are usually long and some are short. Therefore, it is not possible to compare the key at the node with the key you are looking for in a single operation. The key is divided and compared multiple times, and which pointer is traced is determined by the comparison result (size of key). In most cases.
Therefore, when multiple keys are registered with the same beginning and different endings (when registering a lot of keys, this situation will always occur), the comparison at these nodes The problem arises that the same part at the beginning of the key has to be recompared each time.

【0005】また、節点でのキーの比較でキーを複数の
ブロックに分割し、先頭の方のブロックから比較した場
合、得られる情報としては、どこまでのブロックは等し
いが、どこ以降のブロックが大きい又は小さい、という
情報が得られる。しかし、従来の木構造では、節点での
キーの比較結果によりポインタをたどるときにキーが大
きいか小さいかの情報しか利用しておらず、節点での比
較で得られる情報を十分に利用していないという問題が
ある。
When the key is divided into a plurality of blocks by comparing the keys at the nodes and the comparison is made from the first block, the obtained information is where the blocks are equal but where the subsequent blocks are large. Or information that it is small is obtained. However, in the conventional tree structure, only the information about whether the key is large or small is used when the pointer is traced based on the comparison result of the keys at the nodes, and the information obtained by the comparison at the nodes is fully used. There is a problem that there is no.

【0006】本発明の目的は、このような問題を解決
し、キーの先頭の方が同じで後ろの方が違うキーが有る
場合でも無駄な比較をできるだけ少なくし、また節点で
のキーの比較で得られる情報を十分に利用して、情報探
索の性能を向上させることが可能なデータ構造を提供す
ることにある。
An object of the present invention is to solve such a problem, to minimize unnecessary comparison even when there is a key having the same key at the beginning and a different key at the rear, and comparing keys at nodes. It is to provide a data structure capable of improving the performance of information search by fully utilizing the information obtained in.

【0007】[0007]

【課題を解決するための手段】上記目的を達成するため
に、本発明のデータ構造(木構造)では、キーを複数登
録する場合に、それぞれのキーを比較しやすい大きさの
ブロックに分割し、キーの比較を先頭の方のブロックか
らブロック毎に行い、先頭の方のブロックが等しく後ろ
の方のブロックが異なる場合に、等しい部分のブロック
は一つだけ保持し、異なる部分以降のブロックを木構造
のデータ構造になるようにポインターでつないで保持す
ることに特徴がある。
In order to achieve the above object, in the data structure (tree structure) of the present invention, when a plurality of keys are registered, each key is divided into blocks of a size easy to compare. , The key comparison is performed for each block from the first block, and when the first block is the same and the second block is different, only one block of the same part is retained and blocks after the different part are retained. It is characterized by holding it by connecting it with a pointer so that it becomes a tree-structured data structure.

【0008】[0008]

【作用】本発明のデータ構造では、節点からポイントさ
れた先の節点には、ポイント元の節点にセットされてい
るキーと先頭の方から比較し、異なっている所より後ろ
の部分のブロックのみがセットされている。このため、
目的のキーと節点にセットされているキーの先頭の部分
が同じで後ろの部分が違う場合、その節点からポイント
された次の節点でのキーの比較では、前の節点でのキー
の比較で異なった部分が現れた所より後ろの比較のみを
行えば良い。このため、先頭の部分が同じで後ろの部分
が異なるキーが複数登録されている場合のキーの探索時
に各節点で無駄な比較を行わなくても良い。
In the data structure of the present invention, the node pointed to from the node is compared with the key set in the node that is the point of origin from the beginning, and only the blocks after the point where they differ are compared. Is set. For this reason,
If the beginning part of the target key and the key set in the node are the same, but the back part is different, in the key comparison at the next node pointed from that node, the key comparison at the previous node is Only the comparison after the point where the different parts appear should be performed. Therefore, when a plurality of keys having the same head portion but different tail portions are registered, it is not necessary to perform unnecessary comparison at each node when searching for a key.

【0009】また、本発明のデータ構造では、節点に複
数のブロックを持ち、その各ブロック毎にポインタを持
っている。そして、キーの探索を行う場合、節点でキー
の比較を行い、どのブロックまでが等しくどのブロック
から異なるかにより、二つ以上のポインタの中からどの
ポインタをたどるかを決定できる。この結果、情報探索
の性能が向上する。
Further, in the data structure of the present invention, each node has a plurality of blocks, and each block has a pointer. Then, when searching for a key, it is possible to determine which pointer is to be traced from two or more pointers by comparing the keys at the nodes and determining which block is the same and which block is different. As a result, the information search performance is improved.

【0010】[0010]

【実施例】以下、本発明の実施例を図面により詳細に説
明する。図1は、本発明の一実施例であるデータ構造に
7つのキーを登録したときのデータ構造の図である。図
2は、図1のデータ構造の節点の構成の詳細を示した図
である。図2において1は1つ以上の連続したブロック
をセットするエリアであり、2は各ブロック毎に持つポ
インタのエリアで、そのブロックより前のブロックは等
しいが、そのブロック以降のブロックが異なり、且つそ
のブロックの値よりも小さい値のブロックを持つキーを
示す節点へのポインタ(以下、左のポインタと記す)の
エリアである。3は各ブロック毎に持つポインタのエリ
アで、そのブロックより前のブロックは等しいが、その
ブロック以降のブロックが異なり、且つそのブロックの
値よりも大きい値のブロックを持つキーを示す節点への
ポインタ(以下、右のポインタと記す)のエリアであ
る。
Embodiments of the present invention will now be described in detail with reference to the drawings. FIG. 1 is a diagram of a data structure when seven keys are registered in the data structure according to an embodiment of the present invention. FIG. 2 is a diagram showing details of the configuration of nodes in the data structure of FIG. In FIG. 2, 1 is an area in which one or more continuous blocks are set, 2 is an area of a pointer held for each block, blocks before the block are equal, but blocks after the block are different, and It is an area of a pointer (hereinafter, referred to as a left pointer) to a node indicating a key having a block having a value smaller than the value of the block. Reference numeral 3 denotes an area of a pointer held for each block. A pointer to a node indicating a key having a block which is equal to the block before the block but different from the block after the block and has a value larger than the value of the block. This area (hereinafter referred to as the right pointer) is the area.

【0011】図1は、A,B,C,D,E,F、及びG
の7つのキーを登録した場合のデータ構造を示してい
る。4のrootは木構造の根の節点を示すポインタで
ある。A[n]は、キーAのn番目のブロックを示し、
同様にB[n],C[n],…G[n]はそれぞれのキ
ーのn番目のブロックを示す。NILはキーの終端を示
すブロックである。NILは可変長のキー登録を可能と
するために設けたものであり、固定長のキー登録のみを
行う場合NILは必要ない。図1のデータ構造に登録さ
れているキーの長さ(ブロック数)を表1に示す。表2
にそれぞれのキーの大小関係を示す。
FIG. 1 shows A, B, C, D, E, F, and G.
7 shows the data structure when the seven keys are registered. Root 4 is a pointer indicating the node of the root of the tree structure. A [n] indicates the nth block of the key A,
Similarly, B [n], C [n], ... G [n] indicate the nth block of each key. NIL is a block indicating the end of the key. The NIL is provided to enable variable-length key registration, and NIL is not necessary when only fixed-length key registration is performed. Table 1 shows the lengths (number of blocks) of the keys registered in the data structure of FIG. Table 2
Shows the magnitude relationship of each key.

【0012】[0012]

【表1】 [Table 1]

【0013】[0013]

【表2】 [Table 2]

【0014】まず、本データ構造へのキーの登録手順を
示しながら、本データ構造を説明する。キーがなにも登
録されていない状態では、木の根を示すroot4には
0がセットされている。この状態でキーAを登録する場
合、root4に節点5のアドレスをセットし、節点5
にキーAの全てのブロックをセットする。A[5]のブ
ロックの後には、キーAの終端を示すNILをセットし
ておく。
First, this data structure will be described by showing the procedure for registering a key in this data structure. In the state where no key is registered, 0 is set in the root4 indicating the root of the tree. When registering key A in this state, set the address of node 5 to root4 and
Set all blocks of key A to. After the block of A [5], NIL indicating the end of the key A is set.

【0015】次に、この状態にキーBを登録する場合、
まずroot4が指す節点5にセットされているキーA
と、これから登録するキーBを先頭から比較する。キー
AとキーBは、先頭のブロックから異なっており、A
[1]よりB[1]の方が小さい。そこでA[1]の左
のポインタをチェックする。ポインタに何もセットされ
ていないので新しい節点6を作成し、節点6のアドレス
をA[1]の左のポインタにセットし、節点6にキーB
をセットする。
Next, when registering the key B in this state,
First, the key A set at the node 5 pointed to by root4
Then, the key B to be registered is compared from the beginning. Key A and key B are different from the first block,
B [1] is smaller than [1]. Therefore, the pointer on the left of A [1] is checked. Since nothing is set in the pointer, a new node 6 is created, the address of node 6 is set in the pointer on the left of A [1], and key B is set in node 6.
Set.

【0016】次に、この状態にキーCを登録する場合、
まずroot4が指す節点5にセットされているキーA
と、これから登録するキーCを先頭から比較する。キー
AとキーCは、先頭のブロックから異なっており、A
[1]よりC[1]の方が大きい。そこでA[1]の右
のポインタをチェックする。ポインタに何もセットされ
ていないので新しい節点7を作成し、節点7のアドレス
をA[1]の右のポインタにセットし、節点7にキーC
をセットする。
Next, when registering the key C in this state,
First, the key A set at the node 5 pointed to by root4
And the key C to be registered is compared from the beginning. Key A and key C are different from the first block,
C [1] is larger than [1]. Therefore, the pointer to the right of A [1] is checked. Since nothing has been set in the pointer, a new node 7 is created, the address of node 7 is set in the pointer to the right of A [1], and key C is set in node 7.
Set.

【0017】つまり、キーA、キーB、及びキーCは1
番目のブロックが異なるもの同志で2分木のデータ構造
を構成している。
That is, the keys A, B, and C are 1
The second block is different, but the data structure of the binary tree is composed of comrades.

【0018】次に、この状態にキーDを登録する場合、
まずroot4が指す節点5にセットされているキーA
と、これから登録するキーDを先頭から比較する。キー
AとキーDは、1番目、2番目、及び3番目のブロック
は等しいが、4番目のブロックが異なりA[4]よりD
[4]の方が大きい。そこでA[4]の右のポインタを
チェックする。ポインタに何もセットされていないので
新しい節点8を作成し、節点8のアドレスをA[4]の
右のポインタにセットする。節点8にキーDをセットす
るが、そのときにキーAのブロックと等しいD[1],
D[2]、及びD[3]はセットせずに、キーAと異な
るD[4]以降のブロックのみをセットする。
Next, when registering the key D in this state,
First, the key A set at the node 5 pointed to by root4
And the key D to be registered is compared from the beginning. The key A and the key D are the same in the first, second, and third blocks, but are different in the fourth block from A [4] to D.
[4] is larger. Therefore, the pointer to the right of A [4] is checked. Since nothing is set in the pointer, a new node 8 is created and the address of the node 8 is set in the pointer to the right of A [4]. The key D is set at the node 8, and at that time D [1], which is equal to the block of the key A,
D [2] and D [3] are not set, and only blocks after D [4] different from the key A are set.

【0019】次に、この状態にキーEを登録する場合、
まずroot4が指す節点5にセットされているキーA
と、これから登録するキーEを先頭から比較する。キー
AとキーEは、1番目、2番目、及び3番目のブロック
は等しいが、4番目のブロックが異なりA[4]よりE
[4]の方が大きい。そこでA[4]の右のポインタを
チェックする。A[4]の右のポインタはアドレスがセ
ットされているので、そのポインタが指す節点8にセッ
トされているキーDとこれから登録するキーEを比較す
る。ここで、A[4]の右のポインタには、1番目から
3番目のブロックがキーAと等しいキーのみしかセット
されていないので、節点8でのキーの比較では、1番目
から3番目のブロックの比較は不要である。E[4]と
D[4]を比較するとD[4]よりE[4]のほうが小
さい。そこでD[4]の左のポインタをチェックする。
ポインタに何もセットされていないので新しい節点9を
作成し、節点9のアドレスをD[4]の左のポインタに
セットする。節点9にキーEをセットするが、そのとき
にキーA、及びキーDのブロックと等しいE[1],E
[2]、及びE[3]はセットせずに、キーA、及びキ
ーDと異なるE[4]以降のブロックのみをセットす
る。
Next, when registering the key E in this state,
First, the key A set at the node 5 pointed to by root4
Then, the key E to be registered is compared from the beginning. The key A and the key E are the same in the first, second, and third blocks, but are different in the fourth block from E [4] to E.
[4] is larger. Therefore, the pointer to the right of A [4] is checked. Since the address is set in the pointer on the right of A [4], the key D set in the node 8 pointed to by the pointer is compared with the key E to be registered. Here, since the pointers on the right side of A [4] are set only to the keys in which the first to third blocks are equal to the key A, the comparison of the keys at the node 8 indicates that the first to third blocks are the same. No block comparison is necessary. Comparing E [4] and D [4], E [4] is smaller than D [4]. Therefore, the pointer on the left of D [4] is checked.
Since nothing is set in the pointer, a new node 9 is created, and the address of the node 9 is set in the pointer to the left of D [4]. The key E is set at the node 9, and at that time, E [1], E equal to the blocks of the key A and the key D are set.
[2] and E [3] are not set, and only blocks after E [4] different from keys A and D are set.

【0020】つまり、本データ構造ではn番目までのブ
ロックが等しくn+1番目以降のブロックが異なるキー
同志で2分木を構成する。また、このときにn番目まで
のブロックは1つだけ保持し、共有している。というこ
とに特長がある。
That is, in this data structure, a binary tree is constructed by keys having the same up to the n-th block and different n + 1-th and subsequent blocks. At this time, only one block up to the nth block is held and shared. There is a feature in that.

【0021】次に、可変長のキー登録でのみ発生する特
殊なケースを説明する。A,B,C,D、及びEのキー
が登録されている状態にキーFを登録する場合、まずr
oot4が指す節点5にセットされているキーAと、こ
れから登録するキーFを先頭から比較する。キーAとキ
ーFは、先頭のブロックから異なっており、A[1]よ
りF[1]のほうが大きい。そこで、A[1]の右のポ
インタをチェックする。A[1]の右のポインタはアド
レスがセットされているので、そのポインタが指す節点
7にセットされているキーCとこれから登録するキーF
を比較する。キーCとキーFは1番目、及び2番目のブ
ロックは等しいが、キーCは2つのブロックしかなく、
キーFは4つのブロックからなる。そこで、キーCの終
端を示すブロックNILとF[3]を比較し、(NIL
はいずれのブロックの値よりも小さい値をもつものとし
た場合)NILよりもF[3]の方が大きいので、キー
Cの終端を示すNILの右のポインタをチェックする。
このNILの右のポインタに何もセットされていないの
で新しい節点10を作成し、節点10のアドレスをキー
Cの終端を示すNILの右のポインタにセットする。節
点10にキーFをセットするが、そのときにキーCのブ
ロックと等しいF[1]、及びF[2]はセットせず
に、キーCと異なるF[3]以降のブロックのみをセッ
トする。
Next, a special case that occurs only when a variable-length key is registered will be described. When registering the key F while the keys A, B, C, D, and E are registered, first, r
The key A set at the node 5 pointed by the boot 4 and the key F to be registered now are compared from the beginning. The key A and the key F are different from the first block, and F [1] is larger than A [1]. Therefore, the pointer to the right of A [1] is checked. Since the address is set in the pointer on the right of A [1], the key C set at the node 7 pointed to by the pointer and the key F to be registered from now on.
To compare. The keys C and F are the same in the first and second blocks, but the key C has only two blocks.
Key F consists of four blocks. Therefore, the block NIL indicating the end of the key C is compared with F [3], and (NIL
Is F [3] is larger than NIL (assuming that each block has a value smaller than the value of any block), the pointer to the right of NIL indicating the end of key C is checked.
Nothing is set in the pointer to the right of this NIL, so a new node 10 is created, and the address of node 10 is set to the pointer to the right of NIL indicating the end of key C. The key F is set at the node 10, but F [1] and F [2], which are equal to the block of the key C, are not set at that time, and only the blocks of F [3] and subsequent blocks different from the key C are set. ..

【0022】次に、上記の状態にキーGをセットする場
合、まずroot4が指す節点5にセットされているキ
ーAと、これから登録するキーGを先頭から比較する。
キーAとキーGは、先頭のブロックから異なっており、
A[1]よりG[1]のほうが小さい。そこで、A
[1]の左のポインタをチェックする。A[1]の左の
ポインタはアドレスがセットされているので、そのポイ
ンタが指す節点6にセットされているキーBと、これか
ら登録するキーGを比較する。キーBとキーGは1番目
のブロックは等しいが、キーBは4つのブロックがあ
り、キーGは1つのブロックしかない。そこで、キーG
の終端を示すブロックNILとB[2]を比較し、B
[2]よりもNILの方が小さいので、B[2]の左の
ポインタをチェックする。このB[2]の左のポインタ
になにもセットされていないので新しい節点11を作成
し、節点11のアドレスをB[2]の左のポインタにセ
ットする。節点11にキーGをセットするが、そのとき
にキーBのブロックと等しいG[1]はセットせずに、
キーGの終端を示すNILのみをセットする。
Next, when the key G is set in the above state, first, the key A set at the node 5 pointed by the root 4 and the key G to be registered are compared from the beginning.
Key A and Key G are different from the first block,
G [1] is smaller than A [1]. So A
Check the pointer to the left of [1]. Since the address is set to the pointer on the left of A [1], the key B set at the node 6 pointed to by the pointer is compared with the key G to be registered. Key B and key G have the same first block, but key B has four blocks and key G has only one block. So key G
The block NIL indicating the end of B is compared with B [2], and B
Since NIL is smaller than [2], the pointer to the left of B [2] is checked. Since nothing has been set in the left pointer of B [2], a new node 11 is created, and the address of the node 11 is set in the left pointer of B [2]. The key G is set at the node 11, but G [1] equal to the block of the key B is not set at that time,
Only NIL indicating the end of the key G is set.

【0023】以上のように本データ構造では、キーの終
端を示すブロックNILを使用することにより可変長の
キーも登録することができる。また、n番目までのブロ
ックが等しく、n+1番目以降のブロックが異なるキー
同志で2分木を構成しているので、目的のキーを探すと
きに重複している部分の無駄な比較が一切必要ない。更
に、2分木を構成するこれらのキーで、n番目までのブ
ロックを共有し1つしか保持しないので、重複するデー
タを複数セットする必要がなく、データ構造を作成する
ときの時間が短縮される。
As described above, in this data structure, a variable length key can also be registered by using the block NIL indicating the end of the key. In addition, since the n-th block is the same and the n + 1-th block and thereafter are different keys, a binary tree is formed, so that no unnecessary comparison of overlapping parts is required when searching for a target key. .. Furthermore, these keys that make up the binary tree share up to the nth block and hold only one, so there is no need to set multiple duplicate data and the time to create the data structure is shortened. It

【0024】本データ構造において、既に登録されてい
るキーの中から目的のキーを探索するときの手順は、前
に示したキーの登録のときに、新規の節点を追加する所
を探すときと同様の手順でポインタをたどることによ
り、目的のキーの探索が行える。この場合も、重複する
部分の無駄な比較がなく、キーの探索時間が短縮され
る。
In this data structure, the procedure for searching for a target key from the already registered keys is as follows when searching for a new node to be added when registering the key shown above. The target key can be searched by following the pointer in the same procedure. Also in this case, there is no wasteful comparison of overlapping portions, and the key search time is shortened.

【0025】次に、本データ構造から、目的のキーを削
除するときの手順を説明する。キーを削除する場合、ま
ず前に示したキー探索の手順で削除するキーがセットさ
れている節点を探す。そして、その節点にセットされて
いるポインタの状態によってキーの削除手順が異なる。
まず、削除するキーがセットされている節点にポインタ
が1つもセットされていない場合の削除手順を示す。こ
の場合、削除するキーがセットされている節点を指して
いるポインタをクリアすれば良い。例えば、図1のデー
タ構造からキーEを削除する場合、キーの探索を行い、
キーEは節点9にセットされていることが分かる。節点
9は、節点8のD[4]の左のポインタから指されてい
るので、節点8のD[4]の左のポインタをクリアすれ
ば節点9がデータ構造から削除され、キーEが削除でき
る。
Next, a procedure for deleting a target key from this data structure will be described. When deleting a key, first find the node in which the key to be deleted is set by the key search procedure shown above. The key deletion procedure differs depending on the state of the pointer set at the node.
First, the deletion procedure when no pointer is set at the node where the key to be deleted is set will be described. In this case, the pointer pointing to the node where the key to be deleted is set may be cleared. For example, when deleting the key E from the data structure of FIG. 1, a key search is performed,
It can be seen that the key E is set at the node 9. Since the node 9 is pointed to by the left pointer of D [4] of the node 8, if the left pointer of D [4] of the node 8 is cleared, the node 9 is deleted from the data structure and the key E is deleted. it can.

【0026】次に、削除するキーがセットされている節
点にポインタがセットされており、且つポインタがセッ
トされているブロックの内、最も後のブロック(以下、
このブロックを置き換え先頭ブロックと記す)のポイン
タが、左のポインタか右のポインタのいずれか一方しか
セットされていない場合の削除手順を示す。この場合、
削除するキーがセットされている節点の置き換え先頭ブ
ロック以降のブロック及びポインタに、置き換え先頭ブ
ロックの左のポインタ又は右のポインタが指す節点のブ
ロック及びポインタの内容を全て移せば良い。例えば、
図1のデータ構造からキーAを削除する場合、キーの探
索を行い、キーAは節点5にセットされていることが分
かる。節点5の中でポインタがセットされているブロッ
クは、A[1]とA[4]だが、A[4]の方が後のブ
ロックなのでA[4]が置き換え先頭ブロックとなる。
A[4]のブロックには右のポインタしかなく、節点8
を指しているので、節点5のA[4]以降のブロック及
びポインタに節点8のブロック及びポインタの内容をコ
ピーする。そうすると図3の状態となる。A[1],A
[2]、及びA[3]は、D[1],D[2]、及びD
[3]と等しいから、節点5にセットされているキーは
AではなくDとなり、このことからキーAの削除が行わ
れていることが分かる。また、その他の登録状態は変わ
っていない。
Next, the pointer is set at the node where the key to be deleted is set, and the last block (hereinafter, referred to as
This block is referred to as a replacement top block), and the deletion procedure is shown when only one of the left pointer and the right pointer is set. in this case,
All the contents of the node block and the pointer pointed by the left pointer or the right pointer of the replacement head block may be transferred to the blocks and pointers after the replacement head block of the node in which the key to be deleted is set. For example,
When the key A is deleted from the data structure of FIG. 1, it is found that the key is searched and the key A is set at the node 5. The blocks in which the pointer is set in the node 5 are A [1] and A [4], but since A [4] is a later block, A [4] becomes the replacement first block.
The block of A [4] has only the right pointer, and the node 8
The contents of the block and the pointer at the node 8 are copied to the block and the pointer after A [4] of the node 5. Then, the state shown in FIG. 3 is obtained. A [1], A
[2] and A [3] are D [1], D [2], and D
Since it is equal to [3], the key set at the node 5 is D instead of A, and it can be seen that the key A is deleted. The other registration statuses have not changed.

【0027】次に、削除するキーがセットされている節
点にポインタがセットされており、且つポインタがセッ
トされているブロックの内、最も後のブロック(置き換
え先頭ブロック)の左のポインタ及び右のポインタの両
方がセットされている場合の削除手順を示す。この場
合、まず削除するキーがセットされている節点の置き換
え先頭ブロックの右のポインタ(左のポインタをたどる
方法も考えられる)が指す節点を根(root)とした
部分木構造を考える。この部分木構造で、各節点の先頭
のブロックの左のポインタだけをたどり、節点の先頭の
ブロックの左のポインタがセットされていない節点(以
下、置き換え元節点と記す)を探す。置き換え元節点が
見つかったら置き換え元節点を指しているポインタを、
置き換え元節点の先頭のブロックの右のポインタの内容
で置き換える。次に、削除するキーがセットされている
節点の置き換え先頭ブロック以降のブロックの内容を置
き換え元節点にセットされているブロックの内容で置き
換える。また削除するキーがセットされている節点の置
き換え先頭ブロックより1つ後のブロック以降のポイン
タを置き換え元節点の2番目以降のブロックのポインタ
で置き換えれば良い。例えば、図4のデータ構造からキ
ーHを削除する場合、キーの探索を行い、キーHは節点
12にセットされていることが分かる。節点12の中で
ポインタがセットされているブロックは、H[4]だけ
なのでH[4]が置き換え先頭ブロックとなる。H
[4]のブロックには右のポインタ及び左のポインタの
両方がセットされている。そこで、H[4]の右のポイ
ンタが指す節点14を根(root)とする部分木構造
で、各節点の先頭のブロックの左のポインタだけをたど
り、節点の先頭のブロックの左のポインタがセットされ
ていない節点(置き換え元節点)を探す。まず節点14
の先頭のブロックの左のポインタにはアドレスがセット
されているのでポインタをたどり、次に節点15をチェ
ックする。節点15の先頭のブロックの左のポインタは
セットされていないので、節点15が置き換え元節点と
なる。置き換え元節点が見つかったので置き換え元節点
を指している節点14のJ[4]の左のポインタを置き
換え元節点15の先頭のブロックK[4]の右のポイン
タの内容で置き換える。次に、削除するキーがセットさ
れている節点12の置き換え先頭ブロックH[4]以降
のブロックを、置き換え元節点15にセットされている
ブロックの内容で置き換え、また削除するキーがセット
されている節点12の置き換え先頭ブロックH[4]よ
り1つ後のブロック以降のポインタを置き換え元節点1
5の2番目以降のブロックのポインタで置き換える。す
ると図5の状態となる。H[1],H[2]、及びH
[3]は、K[1],K[2]、及びK[3]と等しい
はずであるから、節点12にセットされているキーはH
ではなくキーKとなり、このことからキーHの削除が行
われていることが分かる。また、その他のキーの登録状
態は変わっていない。
Next, the pointer is set at the node where the key to be deleted is set, and the leftmost pointer and the rightmost pointer of the last block (replacement head block) of the blocks where the pointer is set. The deletion procedure when both pointers are set is shown. In this case, first, consider a subtree structure in which the node pointed by the right pointer (following the method of tracing the left pointer) of the replacement head block of the node in which the key to be deleted is set is the root. In this subtree structure, only the pointer on the left of the block at the beginning of each node is traced to find a node for which the pointer on the left of the block at the beginning of the node is not set (hereinafter referred to as replacement source node). When the replacement source node is found, set the pointer pointing to the replacement source node to
Replace with the contents of the pointer on the right of the block at the beginning of the replacement source node. Next, the contents of the blocks after the replacement first block of the node in which the key to be deleted is set are replaced with the contents of the block set in the replacement source node. Further, it is sufficient to replace the pointers of the blocks after the first block after the replacement of the node in which the key to be deleted is set with the pointers of the second and subsequent blocks of the replacement original node. For example, when the key H is deleted from the data structure of FIG. 4, it is found that the key H is searched and the key H is set at the node 12. Since the block in which the pointer is set in the node 12 is only H [4], H [4] becomes the replacement top block. H
Both the right pointer and the left pointer are set in the block [4]. Therefore, in the subtree structure in which the node 14 pointed by the right pointer of H [4] is a root, only the left pointer of the head block of each node is traced, and the left pointer of the head block of the node is Search for unset nodes (replacement original nodes). First, node 14
Since the address has been set in the pointer on the left of the first block of, the pointer is traced, and then the node 15 is checked. Since the pointer to the left of the head block of the node 15 is not set, the node 15 becomes the replacement source node. Since the replacement source node is found, the left pointer of J [4] of the node 14 pointing to the replacement source node is replaced with the content of the right pointer of the leading block K [4] of the replacement source node 15. Next, the block after the replacement head block H [4] of the node 12 in which the key to be deleted is set is replaced with the contents of the block set in the replacement source node 15, and the key to be deleted is set. Replacement of the node 12 The pointer after the block one block after the leading block H [4] is replaced with the node 1
Replace with the pointers of the second and subsequent blocks of block 5. Then, the state shown in FIG. 5 is obtained. H [1], H [2], and H
[3] should be equal to K [1], K [2], and K [3], so the key set at node 12 is H
Instead of the key K, it can be seen that the key H has been deleted. Also, the registration status of other keys has not changed.

【0028】以上のように、本データ構造からのキーの
削除の手順は、2分木のデータ構造からキーを削除する
ときの手順と類似している。ただし、削除するキーがセ
ットされている節点を探索するときの手順は前に示した
ものが使用できるので、この場合も、重複する部分の無
駄な比較がなく、この分の時間が短縮できる。
As described above, the procedure for deleting a key from this data structure is similar to the procedure for deleting a key from the binary tree data structure. However, since the procedure shown above can be used when searching for the node in which the key to be deleted is set, in this case as well, there is no wasteful comparison of overlapping parts and the time can be shortened by this amount.

【0029】また、本データ構造は2分木の考えを使用
しており、各節点はより大きいものへのポインタ、又は
より小さいものへのポインタでつながれているので、本
データ構造に登録されたキーはおのずとソートされてい
ることは明らかである。
Since this data structure uses the idea of a binary tree and each node is connected by a pointer to a larger one or a pointer to a smaller one, it is registered in this data structure. Clearly the keys are naturally sorted.

【0030】このように、本実施例に示したデータ構造
においては、可変長のキーの登録、探索、削除、及びソ
ートを行うことができる。本実施例では、n番目までの
ブロックが等しくn+1番目以降のブロックが異なるキ
ー同志で通常の2分木を構成するものであるが、この他
にn番目までのブロックが等しくn+1番目以降のブロ
ックが異なるキー同志でAVL木を構成する方法、最適
木を構成する方法、2−3木を構成する方法等さまざま
な方法が考えられるので、キー探索の最悪の場合の時間
を短縮する必要がある場合は、これらの方法を使用する
こともできる。
As described above, in the data structure shown in this embodiment, it is possible to register, search, delete, and sort a variable-length key. In the present embodiment, a normal binary tree is formed by keys having the same n-th block and different n + 1-th and subsequent blocks, but in addition to this, the n-th block is equal and the n + 1-th and subsequent blocks are the same. Since various methods such as a method of forming an AVL tree with different keys, a method of forming an optimal tree, and a method of forming a 2-3 tree can be considered, it is necessary to shorten the time in the worst case of key search. If desired, these methods can also be used.

【0031】[0031]

【発明の効果】以上説明したように、本発明によれば、
可変長のキーの登録、探索、削除、及びソートを行うこ
とができるデータ構造を作ることができる。このとき、
本データ構造ではキーの比較を先頭の方のブロックから
ブロック毎に行い、先頭の方のブロックが等しく後ろの
方のブロックが異なる場合に、等しい部分のブロックは
一つだけ保持し、異なる部分以降のブロックを木構造の
データ構造になるようにポインターでつないで保持して
いる。このため、目的のキーが登録されている節点、ま
たは目的のキーを追加する所を探索するときに、キーの
内容が重複する部分の無駄な比較がない。また、キーの
追加の場合は、キーの重複する部分のデータのセットは
1回だけでよい。更に、通常の2分木の場合、1つの節
点での比較により、 ・等しい ・大きい ・小さい の三つの情報しか得られない。このため、一つの節点で
の比較結果により、2つのポインタの中から1つのポイ
ンタを選んでたどることしかできない。しかし、本発明
の方式では、一つの節点での比較により、 ・等しい ・どこのブロックまで等しく、どこ以降のブロックが大
きい ・どこのブロックまで等しく、どこ以降のブロックが小
さい のように、より詳しい情報を得ることができる。このた
め、一つの節点での比較結果により、2つ以上のポイン
タの中から1つのポインタを選んでたどることができ
る。従って、目的のキーを探索し目的のキーがセットさ
れている節点にたどり着くまでに辿らなければならない
ポインタの数が削減される。そのため、従来の木構造の
データ構造でキーの登録、探索、削除、及びソートを実
施する場合より短い時間でこれらの機能を実現できる。
また、多くのキーを登録し、キーの重複する部分が多い
場合は、バイナリサーチと比較しても、より短い時間で
探索を実行することができる。
As described above, according to the present invention,
Data structures can be created that allow for variable length key registration, search, deletion, and sorting. At this time,
In this data structure, key comparison is performed for each block from the first block, and when the first block is the same and the second block is different, only one block of the same part is retained and after the different part The blocks are stored by connecting them with pointers so that they become a tree-structured data structure. Therefore, when searching for a node in which the target key is registered or a place where the target key is added, there is no wasteful comparison of the portions where the key contents overlap. In addition, in the case of adding a key, the data set in the overlapping portion of the key needs to be set only once. Furthermore, in the case of a normal binary tree, the comparison at one node yields only three pieces of information: equal, large, and small. Therefore, only one pointer can be selected from the two pointers and traced according to the comparison result at one node. However, in the method of the present invention, by comparison at one node, it is more detailed such as: equal, to which block is equal, where to be large block, to which block is equal, and after which block is small. You can get information. Therefore, one pointer can be selected and traced from two or more pointers according to the comparison result at one node. Therefore, the number of pointers required to search for the target key and reach the node where the target key is set is reduced. Therefore, these functions can be realized in a shorter time than when performing key registration, search, deletion, and sorting with a conventional tree-structured data structure.
In addition, when many keys are registered and there are many overlapping keys, the search can be executed in a shorter time than the binary search.

【図面の簡単な説明】[Brief description of drawings]

【図1】本発明の一実施例であるデータ構造にA,B,
C,D,E,F、及びGの7つのキーを登録した場合の
データ構造を示す図である。
FIG. 1 is a block diagram showing a data structure of A, B,
It is a figure which shows the data structure at the time of registering seven keys of C, D, E, F, and G.

【図2】節点の構成を示す図である。FIG. 2 is a diagram showing a configuration of nodes.

【図3】図1のデータ構造からキーAを削除した後のデ
ータ構造を示す図である。
FIG. 3 is a diagram showing a data structure after key A is deleted from the data structure shown in FIG.

【図4】本発明の一実施例であるデータ構造にH,I,
J,K,L、及びMの6つのキーを登録した場合のデー
タ構造を示す図である。
FIG. 4 shows H, I, and
It is a figure which shows the data structure at the time of registering six keys of J, K, L, and M.

【図5】図4のデータ構造からキーHを削除した後のデ
ータ構造を示す図である。
5 is a diagram showing a data structure after deleting a key H from the data structure shown in FIG. 4;

【符号の説明】[Explanation of symbols]

1…ブロックをセットするエリア、 2…左のポインのタエリア、 3…右のポインタのエリア、 4…rootポインタ、 5〜17…節点。 1 ... area for setting block, 2 ... left pointer area, 3 ... right pointer area, 4 ... root pointer, 5-17 ... node.

Claims (1)

【特許請求の範囲】 【請求項1】探索を目的としたデータ構造において、デ
ータを識別するための識別子(以下、キーと記す)を複
数登録する場合に、それぞれのキーを一つ以上に分割し
(分割したキーを以下、ブロックと記す)、キーの比較
を先頭の方のブロックからブロック毎に行い、キーの先
頭の方のブロックが等しくキーの後ろの方のブロックが
異なる場合に、等しい部分のブロックは一つだけ保持
し、異なる部分以降のブロックを木構造のデータ構造に
なるようにポインターでつないで保持することを特徴と
する木構造データ構造による高速探索方式。
What is claimed is: 1. When a plurality of identifiers (hereinafter referred to as keys) for identifying data are registered in a data structure for the purpose of searching, each key is divided into one or more. (Divided keys are referred to as blocks below), the keys are compared from the first block to the last block, and if the first block of the key is the same and the second block of the key is different, the same. A high-speed search method using a tree-structured data structure, in which only one block is retained, and blocks following different portions are connected by a pointer so that the block has a tree-structured data structure.
JP3154377A 1991-06-26 1991-06-26 High-speed search method using tree-structured data structure Pending JPH052607A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP3154377A JPH052607A (en) 1991-06-26 1991-06-26 High-speed search method using tree-structured data structure

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP3154377A JPH052607A (en) 1991-06-26 1991-06-26 High-speed search method using tree-structured data structure

Publications (1)

Publication Number Publication Date
JPH052607A true JPH052607A (en) 1993-01-08

Family

ID=15582823

Family Applications (1)

Application Number Title Priority Date Filing Date
JP3154377A Pending JPH052607A (en) 1991-06-26 1991-06-26 High-speed search method using tree-structured data structure

Country Status (1)

Country Link
JP (1) JPH052607A (en)

Similar Documents

Publication Publication Date Title
JP2670383B2 (en) Prefix search tree with partial key branch function
US6564211B1 (en) Fast flexible search engine for longest prefix match
US5488717A (en) MTree data structure for storage, indexing and retrieval of information
US5978795A (en) Temporally ordered binary search method and system
CN107111623A (en) Parallel History Search and Encoding for Dictionary-Based Compression
JPH11212980A (en) Production of index and retrieval method
US7873041B2 (en) Method and apparatus for searching forwarding table
US7756859B2 (en) Multi-segment string search
JPH10240754A (en) Text data registration search method
US7222129B2 (en) Database retrieval apparatus, retrieval method, storage medium, and program
JPH08194718A (en) Document retrieval method and device
JP2001527240A (en) Management in data structures
US20170242880A1 (en) B-tree index structure with grouped index leaf pages and computer-implemented method for modifying the same
JP3518933B2 (en) Structured document search method
CN111581440B (en) Hardware accelerated B+ tree operation device and method thereof
JP3284064B2 (en) Digital search device
JPH052607A (en) High-speed search method using tree-structured data structure
JP3859044B2 (en) Index creation method and search method
JPH08190571A (en) Document search method
JPH0581102A (en) System for controlling table
JP2880192B2 (en) Character string search method and apparatus
CN120123551B (en) Apparatus, methods, devices and computer-readable storage media for processing data
US20150278259A1 (en) Entry insertion apparatus, method, and program
JP3087701B2 (en) Exclusive control unit
JPH09305449A (en) Database management system