Communication method based on double-array prefix tree, server and storage medium

By using double-array prefix tree structure to store device IDs in the Internet of Things and industrial Internet, the problem of device ID encoding occupies a lot of memory and low query efficiency is solved, and efficient device encoding storage and query is achieved.

CN119155278AInactive Publication Date: 2024-12-17CHINA UNICOM ONLINE INFORMATION TECHNOLOGY CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411350053.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-26
Publication Date
2024-12-17
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In the field of the Internet of Things and industrial Internet, device ID encoding method occupies a large amount of memory and is inefficient in querying. Especially when there are many devices, the ID generated by the existing unique numbering algorithm and ordinary Trie tree storage method cannot effectively solve this problem.

Method used

The communication method based on the double-array prefix tree is adopted to generate the device ID through device type and region encoding, encode the device location information into the ID, and store it using the double-array prefix tree structure to achieve efficient device encoding storage and query.

Benefits of technology

It effectively reduces memory usage, improves query efficiency, and can efficiently manage information and location information of a large number of devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119155278A_ABST
    Figure CN119155278A_ABST
Patent Text Reader

Abstract

The invention discloses a communication method based on a double-array prefix tree, a server and a storage medium, and belongs to the field of communication, and the method comprises the following steps: 1, a terminal device is connected with the server, and sends a heartbeat packet to the server, and the heartbeat packet carries a device ID of the terminal device; step 2, the server receives the heartbeat packet, analyzes the heartbeat packet to obtain a device ID, constructs a double-array prefix tree for the device ID, the connection information of the terminal device and the basic information, and stores the double-array prefix tree; and 3, when the terminal equipment communicates with the server, the server queries required information of the related terminal equipment through the base array and the check array in the double-array prefix tree. According to the method, the information such as the position and the type of the equipment is coded into the equipment ID, and the information is stored by using a double-array prefix tree structure, so that efficient equipment coding storage is realized, the memory utilization rate is effectively reduced, and the query efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of communications, and in particular relates to a communication method, a server and a storage medium based on a dual array prefix tree. Background Art

[0002] In the communication connection between servers and several devices in the fields of Internet of Things, Industrial Internet, etc., the device ID needs to be encoded to query and locate the information, status and geographic location of the device. The encoding method is usually UUID, snowflake algorithm and other ID generation methods, which map the device information, status and geographic location information with the device ID. The device ID encoding method based on regional coding bits also takes up a lot of memory when there are many devices, and the query efficiency is low.

[0003] There are two ways to store device ID codes. One is to generate a unique device ID with an algorithm and store it in memory and database, with geographic location information as its attribute. The second is to encode the location information into the device ID and store it in memory in a Trie structure.

[0004] The first type of ID generated by a unique numbering algorithm does not contain any device information and is stored in the memory in a mapping manner. When there are many devices, it not only wastes a lot of memory, but is also very inefficient when querying by geographic location.

[0005] Although the second method also encodes the device location information, the Trie tree that stores the device information in a common linked list manner will also waste a lot of memory due to the impact of the implementation, and the query efficiency is low when there are many devices.

[0006] Therefore, a communication method between a server and a large number of devices is needed to solve the above problems. Summary of the invention

[0007] In order to address the deficiencies of the prior art, the present application provides a communication method, a server and a storage medium based on a dual-array prefix tree, which effectively improves the query efficiency compared to mapping and ordinary Trie trees.

[0008] The technical effects to be achieved by this application are achieved through the following solutions: According to a first aspect of the present application, a communication method based on a dual array prefix tree is provided, comprising the following steps: Step 1: The terminal device connects to the server and sends a heartbeat packet to the server, wherein the heartbeat packet carries the device ID of the terminal device; Step 2: The server receives the heartbeat packet, parses the heartbeat packet to obtain the device ID, constructs a double array prefix tree with the device ID, the connection information of the terminal device and the basic information, and stores the tree; Step 3: When the terminal device communicates with the server, the server queries the required information of the relevant terminal device through the base and check arrays in the double array prefix tree.

[0009] Preferably, the device ID is encoded in the form of device type, region code and device serial number.

[0010] Preferably, the specific method of constructing the dual array prefix tree in step 2 is: The device ID is used as the key, the connection information of the terminal device in the server and the basic information of the terminal device are used as the value to form a key-value pair combination, and the key-value pair combination is put into a double array prefix tree by modifying the base and check arrays, and stored through leaf nodes.

[0011] Preferably, after constructing the dual array prefix tree, the step further includes: the terminal device sends periodic heartbeat packets to the server, the server periodically receives the heartbeat packets, and marks the terminal device as in operation; if the heartbeat packets are not received within a specified period, the terminal device is marked as in abnormal state.

[0012] Preferably, in step 3, the communication between the terminal device and the server includes an operation event reported by the terminal device, the operation event includes the device ID, and after the server locates the relevant terminal device through the base and check arrays in the dual array prefix tree, it stores the operation event and performs corresponding event processing.

[0013] Preferably, in step 3, the communication between the terminal device and the server includes the server sending a broadcast message or issuing an instruction to the area, specifically: The server queries all the terminal devices in the area by querying the device IDs of all the terminal devices connected to it, parsing the base and check arrays corresponding to the double array prefix tree in each device ID; Send broadcast messages or issue instructions to all terminal devices in the area.

[0014] Preferably, in the dual-array prefix tree, the base array stores the base value of the current node, and the check array stores the parent state of the current state for verifying the correctness of the position index. The following state transition equation is used to store the device ID: state[t] = base[s] + code; Among them: state[t] is the state after migration, base[s] is the base number during state migration, code is the migration amount, and the value of code is each digit in the device ID.

[0015] Preferably, when the server receives a broadcast message from an upstream service, it parses the broadcast message and extracts the system code and area code, finds the corresponding position in the base array through the state transfer equation, queries the leaf node in the check array based on the position, and calculates all relevant device IDs from the leaf node.

[0016] According to a second aspect of the present application, a server is provided, comprising: a memory and at least one processor; The memory stores a computer program, and the at least one processor executes the computer program stored in the memory to implement the above-mentioned communication method based on the dual array prefix tree.

[0017] According to a third aspect of the present application, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed, the communication method based on the dual-array prefix tree is implemented.

[0018] According to one embodiment of the present application, the beneficial effect of adopting the communication method based on the dual array prefix tree of the present application is that the method encodes information such as the location and type of the device into the device ID, and uses the dual array prefix tree (DAT) structure to store it, thereby achieving efficient device code storage, effectively reducing memory usage, and improving query efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the embodiments of the present application or the existing technical solutions, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0020] Figure 1 This is a flow chart of a communication method based on a dual array prefix tree in one embodiment of the present application; Figure 2 This is a schematic diagram of the structure of a server in one embodiment of the present application. DETAILED DESCRIPTION

[0021] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.

[0022] like Figure 1 As shown, a communication method based on a dual array prefix tree in an embodiment of the present application includes the following steps: Step 1: The terminal device connects to the server and sends a heartbeat packet to the server, wherein the heartbeat packet carries the device ID of the terminal device; In this step, the device ID is generated using the method of adding the area code to the device number. The geographic location information is encoded into the device ID, which can save memory and facilitate efficient query.

[0023] Geographical location information can be coded according to the "Rules for Compilation of Statistical Zoning Codes and Urban-Rural Division Codes" of the National Bureau of Statistics, and the equipment number is coded in the form of equipment type + equipment serial number. The equipment coding format is defined as follows: system type (1st-2nd digits) - provincial code (3rd-4th digits) - prefecture-level code (5th-6th digits) - county-level code (7th-8th digits) - township-level code (9th-11th digits) - village-level code (12th-14th digits) - equipment type (15th-16th digits) - equipment number (17th-20th digits). For example, if the device code is 12110102001027061001, the first two digits 12 indicate the system type, the third and fourth digits 11 indicate a certain city, the fifth and sixth digits 01 indicate a city district, the seventh and eighth digits 02 indicate a certain district, the ninth to eleventh digits 001 indicate a certain street, the twelfth to fourteenth digits 027 indicate a certain community, the fifteenth to sixteenth digits 06 indicate the device type, and the seventeenth to twentyth digits 1001 indicate the device number. The device code format can be classified more finely according to the actual situation, such as adding other device information such as sub-device type, or adding information such as grid number after the street information.

[0024] The device code itself has the characteristics of a prefix tree. The device information and status are organized together in a dual array prefix tree (DAT) according to the device code and saved in the memory. This can effectively reduce the memory usage in the server and quickly query the current information and status of the node.

[0025] Among them, the heartbeat packet sent by the terminal device to the server for the first time is a registration packet. After parsing, the server will file the terminal device and record the status of the terminal device.

[0026] During operation, the terminal device will periodically send heartbeat packets to the server to maintain the status of the device in the server. If the server continues to receive the heartbeat packets of the terminal device, it will mark the device as running and can send messages and receive event information. If the server does not receive the heartbeat packets of the terminal device within a certain period, the terminal device will be marked as abnormal to remind the staff to perform maintenance, or it will be ignored when sending messages.

[0027] The periodically sent heartbeat packet and registration packet may contain the same information or different information. The registration packet may include not only the device ID but also other device information; the periodically sent heartbeat packet may include only the device ID or information such as the device status.

[0028] Step 2: The server receives the heartbeat packet, parses the heartbeat packet to obtain the device ID, constructs a double array prefix tree with the device ID, the connection information of the terminal device and the basic information, and stores the tree; In this step, the terminal device periodically reports its current status to the server when it is started. Each piece of information will contain the device code of the terminal device, which is encoded in the form of area code + device number.

[0029] The double array prefix tree uses a state machine to encode data. The base and check arrays are used to maintain the state in the state transition equation. The index of the base and check arrays represents a state. The base array stores the offset corresponding to the current state, and the check array stores the parent state of the current state. The state transition equation state[t]= base[s] + code means adding the code code to convert the state from s to t.

[0030] Among them: state[t] is the state after migration, base[s] is the base number during state migration, code is the migration amount, and the value of code is each digit in the device ID.

[0031] Another way of expression is: t = base[s] + code, where s is the current state and t is the state after migration.

[0032] Take the device code 12110102001027061001 as an example. In the state transition equation state[t] = base[s] +code, the value of each digit of the device code is the added code. Therefore, in this solution, the value range of code is 0 to 9. If the device code contains letters AZ, you can customize the code table to convert between code and code.

[0033] The connection information in this step is the socket that the server opens to accept the terminal device connection, which is a programming interface that enables communication between different types of computers; Basic information refers to the information of the device, including device ID and device description, which is stored in the heartbeat packet and obtained by parsing the heartbeat packet.

[0034] In the server, the device ID of the terminal device is used as a keyword and the device ID is saved in a double-array prefix tree. The leaf node stores the device information. When querying, the base and check arrays are queried according to the area code to obtain the device IDs of all terminal devices in the area. Then, instructions can be issued to the device based on the device ID to debug or maintain the device.

[0035] The leaf node is a word or string completed in the double-array prefix tree. The terminal device completes the creation of the device ID double-array prefix tree through the first heartbeat packet. In the subsequent operation, the corresponding device ID can be efficiently queried to obtain detailed information about the device.

[0036] Step 3: When the terminal device communicates with the server, the server queries the required information of the relevant terminal device through the base and check arrays in the double array prefix tree.

[0037] In this step, the communication between the terminal device and the server includes the operation events reported by the terminal device, and the operation events include the device ID. After the server locates the relevant terminal device through the base and check arrays in the double array prefix tree, it stores the operation events and performs corresponding event processing.

[0038] The communication between the terminal device and the server also includes the server sending broadcast messages or issuing instructions to the area, specifically: First, the server queries the device IDs of all connected terminal devices, parses the base and check arrays corresponding to the double-array prefix tree in each device ID, and queries all terminal devices in the area; Then, a broadcast message or instruction is sent to all terminal devices in the area.

[0039] In a specific example in this application: Take the district of a city as an example. There are five terminal devices identified as ti, where i = (1,5). Among them, t1, t2, and t3 are in a certain urban area, and the device codes are 12110102001027061001, 12110102001027061002, and 12110102001027061003, respectively. The 3rd to 14th digits 110102001027 in the device code are administrative area codes, corresponding to a community in a certain urban area; among them, t4 and t5 are located in a certain district, and the device codes are 12110101011001061004 and 12110101011001061005, respectively. The 3rd to 14th digits 110101011001 in the device code are administrative area codes, corresponding to a community in a certain district.

[0040] After device t1 starts, it connects to the server and sends a heartbeat packet. The server parses the heartbeat packet to extract the device code 12110102001027061001, traverses the device code from left to right, and inserts the device code into the double array prefix tree in combination with the state transition equation state[t] = base[s] + code, and puts the terminal connection information into the leaf node. Specifically, the device ID number 12110102001027061001 is used as an example to illustrate the process of inserting DAT as follows: First, we make assumptions and initializations. Assume that characters are encoded using ASCII, and their values ​​are ord(c)-ord('0'), ranging from 0 to 9, that is, the integer values ​​corresponding to characters 1 to 9. Initialize the root node: Usually, the base[0] of the root node is initialized to 1, and check[0] is set to -1 to indicate idle.

[0041] Then insert them one by one according to the device ID number: Insert the first character '1': The value of the character '1' is 1, ord('1') - ord('0') = 1; calculate the insertion position: base[0] + 1 = 1 +1 = 2; Update the base and check arrays: obase[2] is set to a new value, which can be any value. Here, it is set to 3, which is used for child nodes. ocheck[2] = 0, indicating that its parent node is the root node 0, and we get: base: [ 1, 0, 3, 0, ...] check: [-1, -1, 0, -1, ...] Insert the second character '2': The value of the character '2' is 2, ord('2') - ord('0') = 2; calculate the insertion position: base[2] + 2 = 3 +2 = 5; Update the base and check arrays: obase[5] is set to a new value of 4; ocheck[5] = 2, indicating that its parent node is 2, and we get: base: [1, 0, 3, 0, 0, 4, 0, ...] check: [-1, -1, 0, -1, -1, 2, -1, ...] Insert the third character '1': The value of the character '1' is 1; the insertion position is calculated: base[5] + 1 = 4 + 1 = 5, but it is found that position 5 is already occupied, so a conflict occurs and a new base value needs to be selected; Select base[5] value as 6 and recalculate the insertion position: Insertion position: base[5] + 1 = 6 + 1 = 7; Update the base and check arrays: base[7] is set to a new value of 5; check[7] = 5, indicating that its parent node is 5, and we get: base: [1, 0, 3, 0, 0, 6, 0, 5, ...] check: [-1, -1, 0, -1, -1, 2, -1, 5, ...] Insert the fourth character '1': The value of the character '1' is 1; calculate the insertion position: base[7] + 1 = 5 + 1 = 6. A conflict also occurs, so base[7] needs to be adjusted; Suppose we set base[7] to 7 and recalculate: Insertion position: base[7] + 1 = 7 + 1 = 8.

[0042] Update the base and check arrays: base[8] is set to a new value of 6; check[8] = 7; Continue inserting subsequent characters in the same way, calculating the insertion position each time, updating the base and check arrays, and handling possible conflicts. After the above insertion steps, the base and check arrays will gradually fill up, reflecting the path of device ID 12110102001027061001 in the double array prefix tree. The last node should be marked as a terminal node, and the corresponding value of the check array is set to a negative value to indicate that this is a leaf node.

[0043] Similarly, after devices t2, t3, t4, and t5 are started, they connect to the server and send heartbeat packets. The server parses the heartbeat packets to extract the device code, traverses the device code from left to right, and inserts the device code into the double array prefix tree based on the state transfer equation state[t] = base[s] +code, and puts the terminal connection information into the leaf node.

[0044] When the server receives a command message from the upstream service for a terminal device, it parses the device code in the message, traverses the device code from left to right, and searches for the terminal device information in the double array prefix tree constructed above. After finding the terminal device information, it issues a command to the terminal device through the connection information.

[0045] When the server receives a broadcast message from an upstream service, it parses the message and extracts the system code and region code, that is, the 1st to 14th bits in the device code, and finds the corresponding position p in the base array in combination with the state transition equation. p is the subscript of the base array. Then it traverses the check array to query all subscripts R with a value of p. Suppose a total of m are found, Ri represents one of the check array subscripts, i=(1, m), and then it traverses the check array to query all subscripts with a value of Ri, and so on until the leaf node in the check array is queried. Through the terminal information stored in all the leaf nodes found, the message is sent to the corresponding device to complete the delivery of the broadcast message.

[0046] In one embodiment of the present application, Figure 2 As shown, a server is disclosed, comprising: a memory 201 and at least one processor 202; The memory 201 stores a computer program, and the at least one processor 202 executes the computer program stored in the memory 201 to implement the above-mentioned communication method based on the dual array prefix tree.

[0047] In one embodiment of the present application, a computer-readable storage medium is disclosed, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed, the communication method based on the dual-array prefix tree is implemented.

[0048] According to an embodiment of the present application, the beneficial effect of using the dual array prefix tree-based communication method of the present application is that the method encodes information such as the location and type of the device into the device ID and stores it using a dual array prefix tree (DAT) structure.

[0049] Since the device ID has many repeated parts, the traditional prefix tree usually uses a fixed-size array or dictionary to represent a node. A fixed array to represent a node will waste a lot of memory and cannot save memory. A dictionary to represent a node has a fixed structure, which wastes a lot of memory when storing a large amount of data, and the pointer operation efficiency is not high. Therefore, the use of this dual-array prefix tree can compress its memory usage, realize efficient device code storage, effectively reduce memory usage, and improve query efficiency.

[0050] It should be noted that the above detailed descriptions are exemplary and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the art to which the present application belongs.

[0051] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should also be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.

[0052] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein.

[0053] In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or inherent to these processes, methods, products, or apparatuses.

[0054] For ease of description, spatially relative terms, such as "above", "above", "on the upper surface of", "above", etc., may be used herein to describe the spatial positional relationship between a device or feature and other devices or features as shown in the figure. It should be understood that spatially relative terms are intended to include different orientations of the device in use or operation in addition to the orientation described in the figure. For example, if the device in the accompanying drawings is inverted, the device described as "above other devices or structures" or "above other devices or structures" will be positioned as "below other devices or structures" or "below other devices or structures". Thus, the exemplary term "above" may include both "above" and "below". The device may also be positioned in other different ways, such as rotated 90 degrees or in other orientations, and the spatially relative descriptions used herein are interpreted accordingly.

[0055] In the above detailed description, reference is made to the accompanying drawings, which form a part of this document. In the accompanying drawings, similar symbols typically identify similar components unless the context indicates otherwise. The illustrated embodiments described in the detailed description, drawings, and claims are not meant to be limiting. Other embodiments may be used, and other changes may be made, without departing from the spirit or scope of the subject matter presented herein.

[0056] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. Communication method based on double array prefix tree, It is characterized in that The steps include: Step 1: The terminal device connects to the server and sends a heartbeat packet to the server. The heartbeat packet carries the device ID of the terminal device. The device ID is encoded in the form of device type, region code and device serial number. Step 2: The server receives the heartbeat packet, parses the heartbeat packet to obtain the device ID, constructs a double array prefix tree with the device ID, the connection information of the terminal device and the basic information, and stores the tree; Step 3: When the terminal device communicates with the server, the server queries the required information of the relevant terminal device through the base and check arrays in the double array prefix tree.

2. The communication method based on the dual array prefix tree according to claim 1, It is characterized in that In step 2, the specific method of constructing a double array prefix tree is: The device ID is used as the key, the connection information of the terminal device in the server and the basic information of the terminal device are used as the value to form a key-value pair combination, and the key-value pair combination is put into a double array prefix tree by modifying the base and check arrays, and stored through leaf nodes.

3. The communication method based on the dual array prefix tree according to claim 1, It is characterized in that After constructing the double array prefix tree, the method further includes: the terminal device sends a periodic heartbeat packet to the server, and the server periodically receives the heartbeat packet and marks the terminal device as a running state; if the heartbeat packet is not received within a specified period, the terminal device is marked as an abnormal state.

4. The communication method based on the dual array prefix tree according to claim 2, It is characterized in that In step 3, the communication between the terminal device and the server includes the operation event reported by the terminal device, and the operation event includes the device ID. After the server locates the relevant terminal device through the base and check arrays in the double array prefix tree, it stores the operation event and performs corresponding event processing.

5. The communication method based on the dual array prefix tree according to claim 2, It is characterized in that In step 3, the communication between the terminal device and the server includes the server sending a broadcast message or issuing an instruction to the area, specifically: The server queries all the terminal devices in the area by querying the device IDs of all the terminal devices connected to it, parsing the base and check arrays corresponding to the double array prefix tree in each device ID; Send broadcast messages or issue instructions to all terminal devices in the area.

6. The communication method based on the dual array prefix tree according to claim 5, It is characterized in that In the dual-array prefix tree, the base array stores the base value of the current node, and the check array stores the parent state of the current state, which is used to verify the correctness of the position index. The following state transition equation is used to store the device ID: state[t] = base[s] + code; Among them: state[t] is the state after migration, base[s] is the base number during state migration, code is the migration amount, and the value of code is each digit in the device ID.

7. The communication method based on the dual array prefix tree according to claim 6, It is characterized in that When the server receives a broadcast message from an upstream service, it parses the broadcast message and extracts the system code and area code, finds the corresponding position in the base array through the state transfer equation, queries the leaf node in the check array based on the position, and calculates all relevant device IDs from the leaf node.

8. A server, It is characterized in that include: memory and at least one processor; The memory stores a computer program, and the at least one processor executes the computer program stored in the memory to implement the communication method based on the dual array prefix tree according to any one of claims 1 to 7.

9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed, the communication method based on the dual-array prefix tree according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Thesaurus fuzzy enquiry method and thesaurus fuzzy enquiry system

    CN101398830A

  • Information processing method and information processing device

    CN103823814A

  • Quick retrieval method for electric power equipment

    CN109388728A

  • Regional code query method and system based on prefix tree and application of regional code query method and system

    CN113407539A

  • Address completion method and device based on double arrays, and storage medium

    CN114818670A