Area coding query method and system based on prefix tree and application thereof
1. A prefix tree-based region coding query method is characterized by comprising the following steps:
s1, connecting all terminals to a server, and sending a heartbeat packet to the server, wherein the heartbeat packet carries a data source object code of the terminal;
s2, the server receives the heartbeat packet, analyzes the heartbeat packet and extracts the region code from the data source object code;
s3, the server establishes a prefix tree, wherein the prefix tree takes region coding as key and takes the connection information of the terminal at the server and the basic information of the terminal as values;
and S4, when information needs to be sent to a certain area, inquiring the basic information of the terminal in the area in the prefix tree through area coding.
2. The method as claimed in claim 1, wherein the data source object code comprises a level identifier, a region code, a resource type code, a type order code, a subtype code, and a subtype order code.
3. The prefix tree-based region encoding query method of claim 1, wherein the data source object encoding is composed of the following parts in sequence: 1 bit level identification code +12 bit zone code +4 bit resource type code +2 bit type sequence code +2 bit sub type sequence code.
4. The method as claimed in claim 1, wherein the basic information of the terminal is stored in a leaf node of the prefix tree.
5. The method as claimed in claim 3, wherein the method for querying by region coding based on the prefix tree is that the prefix tree takes region coding as key, and comprises: and sequentially inserting the 12-bit area codes into the prefix tree from left to right, placing a number into one node, taking the first bit as a root node, taking the following numbers as child nodes in sequence until the area codes are completely inserted into the prefix tree, and placing the basic information of the terminal into the final leaf node.
6. The method as claimed in claim 5, wherein the step S4 for querying the basic information of the terminal in the area in the prefix tree by area coding comprises: and the server side inquires the prefix tree according to the regional code issued by the upstream, sequentially inquires each node from left to right, acquires corresponding terminal basic information if the inquiry can be made, and returns an empty set if the inquiry cannot be made.
7. A prefix tree based area coding query system, comprising:
the terminal is used for sending a heartbeat packet carrying the data source object code of the terminal to the server;
the server is used for receiving and analyzing the heartbeat packet sent from the terminal and extracting the region code from the data source object code in the heartbeat packet;
the modeling module is used for establishing a prefix tree at the server, and the prefix tree takes the region code of each terminal as a key and takes the connection information of each terminal at the server and the basic information of the terminal as values;
and the query module is used for querying the basic information of the terminal in the area in the prefix tree through the area coding.
8. The prefix tree-based region encoding query system of claim 7, wherein the data source object encoding is composed of the following parts in sequence: 1 bit level identification code +12 bit zone code +4 bit resource type code +2 bit type sequence code +2 bit sub type sequence code.
9. The prefix tree based region coding query system of claim 7,
in the modeling module, the method for coding the prefix tree into keys by regions comprises the following steps: inserting 12-bit area codes into a prefix tree from left to right in sequence, placing a number into a node, taking a first digit as a root node, taking the following digits as child nodes in sequence until the area codes are completely inserted into the prefix tree, and placing terminal basic information into the final leaf node;
in the query module, the method for querying the basic information of the terminal in the region in the prefix tree through region coding comprises the following steps: and the server side inquires the prefix tree according to the regional code issued by the upstream, sequentially inquires each node from left to right, acquires corresponding terminal basic information if the inquiry can be made, and returns an empty set if the inquiry cannot be made.
10. Use of the prefix tree based area code query method according to any one of claims 1 to 6, for sending broadcast messages to a specified area in an emergency broadcast system.
Background
In some cases, data is queried according to regional codes, for example, if a broadcast message is sent to a certain region in an emergency broadcast system, corresponding broadcast equipment such as a loudspeaker needs to be queried according to the regional codes.
Disclosure of Invention
The invention provides a prefix tree-based regional coding query method, a prefix tree-based regional coding query system and application thereof, which are used for solving the problems of storage space waste, complicated query process and low efficiency of a regional coding query mode in the prior art and achieving the purposes of saving storage space and improving query efficiency.
The invention is realized by the following technical scheme:
a prefix tree-based regional coding query method comprises the following steps:
s1, connecting all terminals to a server, and sending a heartbeat packet to the server, wherein the heartbeat packet carries a data source object code of the terminal;
s2, the server receives the heartbeat packet, analyzes the heartbeat packet and extracts the region code from the data source object code;
s3, the server establishes a prefix tree, wherein the prefix tree takes region coding as key and takes the connection information of the terminal at the server and the basic information of the terminal as values;
and S4, when information needs to be sent to a certain area, inquiring the basic information of the terminal in the area in the prefix tree through area coding.
The invention provides a prefix tree-based regional code query method, which aims at solving the problems of storage space waste, complicated query process and low efficiency of a regional code query mode in the prior art. After receiving any one heartbeat packet, the server analyzes the heartbeat packet, acquires a data source object code and extracts an area code from the data source object code. And then establishing a prefix tree by the server, wherein the prefix tree established in the application takes the region code as a key and takes the connection information of the terminal at the server and the basic information of the terminal as values, namely, the region code and connection information and the key value pair combination of the basic information of the terminal are put into the prefix tree to obtain the complete structure of the prefix tree. Based on the steps, firstly, a prefix tree is established, and then when information needs to be sent to some specified areas, the basic information of the terminal in the area can be inquired in the prefix tree through the area code of the specified area. The method and the device have the advantages that the prefix tree is incorporated into the query application of the area code, the problems of storage space waste, complicated query process and low efficiency of an area code query mode in the prior art are solved, the characteristics that the area code has a hierarchical structure and the parent-child node relation of the tree structure of the prefix tree are fully utilized, the tree structure relation of the area code is perfectly matched with the tree structure of the prefix tree, only the area code is utilized, other operations such as classification table building are not additionally needed, the storage space is saved, and the query efficiency can be remarkably improved.
Further, the data source object code comprises a level identification code, a region code, a resource type code, a type sequence code, a subtype code and a subtype sequence code.
Further, the data source object code is composed of the following parts in sequence: 1 bit level identification code +12 bit zone code +4 bit resource type code +2 bit type sequence code +2 bit sub type sequence code.
Further, the terminal basic information is stored on a leaf node of the prefix tree.
Further, the method for encoding the prefix tree into keys by regions comprises the following steps: and sequentially inserting the 12-bit area codes into the prefix tree from left to right, placing a number into one node, taking the first bit as a root node, taking the following numbers as child nodes in sequence until the area codes are completely inserted into the prefix tree, and placing the basic information of the terminal into the final leaf node. The method for setting the prefix tree in the scheme can fully utilize the tree structure of the prefix tree, and the tree structure is perfectly combined with the tree structure relationship of the region codes.
Further, the method for querying the basic information of the terminal in the area in the prefix tree through the area coding in step S4 includes: and the server side inquires the prefix tree according to the regional code issued by the upstream, sequentially inquires each node from left to right, acquires corresponding terminal basic information if the inquiry can be made, and returns an empty set if the inquiry cannot be made. By the query method, the basic information of the terminals in the designated area is uniformly collected, and then the server can uniformly send the related information to all the terminals in the designated area.
A prefix tree based area coding query system, comprising:
the terminal is used for sending a heartbeat packet carrying the data source object code of the terminal to the server;
the server is used for receiving and analyzing the heartbeat packet sent from the terminal and extracting the region code from the data source object code in the heartbeat packet;
the modeling module is used for establishing a prefix tree at the server, and the prefix tree takes the region code of each terminal as a key and takes the connection information of each terminal at the server and the basic information of the terminal as values;
and the query module is used for querying the basic information of the terminal in the area in the prefix tree through the area coding.
Further, the data source object code is composed of the following parts in sequence: 1 bit level identification code +12 bit zone code +4 bit resource type code +2 bit type sequence code +2 bit sub type sequence code.
Further, in the modeling module, the method for encoding the prefix tree into keys by regions includes: inserting 12-bit area codes into a prefix tree from left to right in sequence, placing a number into a node, taking a first digit as a root node, taking the following digits as child nodes in sequence until the area codes are completely inserted into the prefix tree, and placing terminal basic information into the final leaf node;
in the query module, the method for querying the basic information of the terminal in the region in the prefix tree through region coding comprises the following steps: and the server side inquires the prefix tree according to the regional code issued by the upstream, sequentially inquires each node from left to right, acquires corresponding terminal basic information if the inquiry can be made, and returns an empty set if the inquiry cannot be made.
The application of the region coding query method is as follows: the method is used for sending broadcast messages to a certain area in the emergency broadcast system, so that the blank of the prior art is filled.
Compared with the prior art, the invention has the following advantages and beneficial effects:
1. the method, the system and the application make full use of the characteristic that the area code has a hierarchical structure and the parent-child node relation of the tree structure of the prefix tree, so that the tree structure relation of the area code is perfectly matched with the tree structure of the prefix tree, only the area code is used, other operations such as classification and table building are not needed, the storage space is saved, and the query efficiency is obviously improved.
2. The invention relates to a prefix tree-based area code query method, a prefix tree-based area code query system and application thereof, wherein the prefix tree setting method can fully utilize the tree structure of a prefix tree, so that the tree structure and the tree structure relationship of area codes are perfectly combined.
3. The area coding query method, the area coding query system and the application thereof based on the prefix tree can be efficiently suitable for sending broadcast messages to a certain area in an emergency broadcast system, and fill the blank in the prior art.
4. The invention relates to a prefix tree-based regional code query method, a prefix tree-based regional code query system and application thereof, which optimize the storage and query efficiency of data associated with administrative regional codes.
Drawings
The accompanying drawings, which are included to provide a further understanding of the embodiments of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the principles of the invention. In the drawings:
FIG. 1 is a schematic flow chart of an embodiment of the present invention;
FIG. 2 is a system diagram of an embodiment of the present invention;
FIG. 3 is a diagram illustrating a region-coded query in accordance with an embodiment of the present invention;
FIG. 4 is a diagram illustrating a prefix tree in an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail below with reference to examples and accompanying drawings, and the exemplary embodiments and descriptions thereof are only used for explaining the present invention and are not meant to limit the present invention. In the description of the present application, it is to be understood that the terms "front", "back", "left", "right", "upper", "lower", "vertical", "horizontal", "high", "low", "inner", "outer", etc. indicate orientations or positional relationships based on those shown in the drawings, and are only for convenience in describing the present invention and simplifying the description, but do not indicate or imply that the device or element being referred to must have a particular orientation, be constructed in a particular orientation, and be operated, and thus should not be construed as limiting the scope of the present application.
Example 1:
fig. 1 shows a prefix tree-based area coding query method, which is used in the field of emergency broadcasting:
s1: the broadcast terminal equipment is connected with the server and sends a heartbeat packet, the heartbeat packet carries a data source object code of the terminal equipment, and the data source object code comprises a 1-bit level identification code + 12-bit administrative region code + 4-bit resource type code + 2-bit type sequential code + 2-bit sub-type sequential code.
S2: based on step S1, the server receives the terminal heartbeat packet, parses the heartbeat packet and extracts the administrative region code, takes the administrative region code as a key, takes the connection information of the terminal in the server and the terminal basic information as values, puts the key value pair combination into the prefix tree, only leaves of the prefix tree will store the terminal information, inserts 12-bit regional codes into the prefix tree from left to right in sequence, puts a number into a node, the first bit as a root node, and the following numbers as children nodes in sequence, inserts the regional codes into the prefix tree in a similar procedure, puts the information of the terminal device into the last leaf node, and the server stores the information of each terminal after parsing.
S3: when a broadcast message is sent to a certain area, inquiring terminal equipment information in a prefix tree through area codes, inquiring each node from left to right in sequence according to the terminal information stored before the area codes issued upstream are inquired, and finally inquiring the terminal information, wherein if an empty set is not returned after the inquiry.
S4: based on step 4, a broadcast message is sent to the terminal device.
The administrative region codes used in this embodiment are administrative region partitions published by the government and have a hierarchical structure, so that storage and query can be performed in a hierarchical manner, and different tables can be queried for region codes of different levels. On the basis, the region coding data can be put in a table, and a field for executing the upper level is added for each node to form a tree-shaped logic structure, so that the judgment of looking up different tables can be avoided, but the administrative region coding is needed to generate the tree-shaped table.
Further, optimization processing is carried out, the administrative region codes contain the characteristic of a tree structure, the characteristic can be used for storing according to a prefix tree (Trie) mode, the prefix tree is used for storing data related to the administrative region codes, only the region codes are needed, other operations are not needed, the storage space is saved, and the query efficiency can be improved.
Example 2:
a prefix tree based area coding query system, as shown in fig. 2, includes:
the terminal is used for sending a heartbeat packet carrying the data source object code of the terminal to the server;
the server is used for receiving and analyzing the heartbeat packet sent from the terminal and extracting the region code from the data source object code in the heartbeat packet;
the modeling module is used for establishing a prefix tree at the server, and the prefix tree takes the region code of each terminal as a key and takes the connection information of each terminal at the server and the basic information of the terminal as values;
and the query module is used for querying the basic information of the terminal in the area in the prefix tree through the area coding.
Preferably, the data source object code is composed of the following parts in sequence: 1 bit level identification code +12 bit zone code +4 bit resource type code +2 bit type sequence code +2 bit sub type sequence code.
Preferably, in the modeling module, the method for encoding the prefix tree into keys by regions includes: inserting 12-bit area codes into a prefix tree from left to right in sequence, placing a number into a node, taking a first digit as a root node, taking the following digits as child nodes in sequence until the area codes are completely inserted into the prefix tree, and placing terminal basic information into the final leaf node;
in the query module, the method for querying the basic information of the terminal in the region in the prefix tree through region coding comprises the following steps: and the server side inquires the prefix tree according to the regional code issued by the upstream, sequentially inquires each node from left to right, acquires corresponding terminal basic information if the inquiry can be made, and returns an empty set if the inquiry cannot be made.
The system of this embodiment may be used to implement the method steps as described in embodiment 1.
Example 3:
a method for broadcasting in a designated area in an emergency broadcasting system, as shown in fig. 3 and 4:
in the emergency broadcast system, broadcast messages need to be sent according to administrative region codes, terminal equipment connected to a server side forms a prefix tree according to the region codes, all terminal equipment information under the region can be searched only by inquiring according to the region codes of the administrative region, and then the broadcast messages are sent to the equipment. Specifically, the method comprises the following steps:
taking wuhan city administrative districts as an example, the existing 6 terminal devices are represented by ti, wherein i is [1,6], resource codes of t1, t2 and t3 are 64201060120010314010101, 64201060120010314010102 and 64201060120010314010103 respectively, administrative district codes of the areas where the terminal devices are located are 420106012001, and the terminal devices are represented in wuhan city (01) wuchang district (06) fruit lake street (012) east lake road community (001) in northwest of Hubei province (42); wherein the resource numbers of t4, t5 and t6 are 64201060110030314010101, 64201060110030314010102 and 64201060110030314010103 respectively, which indicate that the devices are in the southern street (011) vinblastic community (001) in Wuchang district (06) in Wuhan city (01) in Hubei province (42).
When the terminal device t1 connects to the server and sends the heartbeat packet, the server parses the resource code of the device and extracts the region code thereof, for example, the region code of t1 is 420106012001, the region code of t1 is traversed from left to right, the first bit 4 as the child node (n1) of the root node of the prefix tree is inserted into the prefix tree, the second bit 2 as the child node (n2) of n1 is inserted into the prefix tree, the third bit 0 as the child node of n2 is inserted into the prefix tree, the region code is inserted into the prefix tree by the similar steps, and the information of the terminal device is placed in the last leaf node.
When the terminal device t2 connects to the server and sends the heartbeat packet, if the region code of t2 is 420106012001, the region code of t2 is traversed from left to right, the first bit is 4, when the root node of the prefix tree is checked to have 4 nodes, the second bit is checked to be 2, 2 nodes exist in the child nodes of 4, the third bit is checked to be other bits in the region code, and the region code of t2 is the same as the region code of t1, so the terminal device information of t2 is also placed in the last leaf node.
After the terminal device t4 connects to the server and sends the heartbeat packet, for example, the region code of t4 is also 420106011003, and the region code of t4 is traversed from left to right, the first 8 bits are the same as the step of t2, and since there is no 1 in the child nodes of the node n8, the 9 th bit 1 is inserted into the prefix tree as a new child node of n8, and the other bits of the region code are inserted into the prefix tree in turn.
When receiving the broadcast instruction of the upstream service, the server side inquires the terminal equipment information of all target areas in the prefix tree T constructed by using the terminal equipment area codes according to the target area codes in the instruction. If the target area code in the broadcast instruction is 420106012, searching whether a node with the value of area code first value (4) exists in the root node of the prefix tree T, if so, continuing to search a node with the value of area code second value (2) in the node just found, sequentially searching other bits of the area code, for example, all the bits of the area code can be found in the prefix tree T, and searching terminal information kept in all leaf nodes in all subtrees of the node searched finally; if the nodes are not found in the inquiry process, the search is terminated and an empty set is directly returned.
Preferably, the administrative region codes are distinguished according to the province, city, district, street and community levels in the embodiment.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are merely exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Further, the term "connected" used herein may be directly connected or indirectly connected via other components without being particularly described.
- 上一篇:石墨接头机器人自动装卡簧、装栓机
- 下一篇:交易数据流获取方法及装置