Data storage method and device, electronic equipment and storage medium

By storing the start and end values ​​of range-like data in the red and black tree, using the insertion and query mechanism of the red and black tree, the problems of low storage efficiency and slow query speed in the existing technology are solved, and efficient data storage is achieved and query.

CN119311216APending Publication Date: 2025-01-14CHINA TELECOM CORP LTD TECHNOLOGY INNOVATION CENTER +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411347497.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-25
Publication Date
2025-01-14

AI Technical Summary

Technical Problem

When storing range-type data, the storage efficiency is low, the storage space is required, and the query speed is slow, making it difficult to effectively manage a large amount of configuration data in modern gateways and security devices.

Method used

Adopt the red and black tree data structure, by obtaining the starting and ending values ​​of the data to be inserted and the associated strategies, traversing the red and black tree for matching and insertion, using different insertion methods to achieve accurate insertion and merging ranges, and optimizing storage space utilization rate and query efficiency.

Benefits of technology

It improves storage efficiency, reduces storage space requirements, improves query speed and system performance, and ensures data consistency and system stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119311216A_ABST
    Figure CN119311216A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of network security, in particular to a data storage method and device, electronic equipment and a storage medium, which are used for improving storage efficiency and saving storage space. The method comprises the following steps: acquiring to-be-inserted data, wherein the to-be-inserted data comprises a to-be-inserted initial value and a to-be-inserted end value of a to-be-inserted range, and a to-be-inserted strategy; the red-black tree is traversed, the matching result of the end value of each node of the red-black tree and the end value to be inserted is determined, and each node of the red-black tree is used for storing the initial value and the end value of the corresponding range and the strategy associated with the range; and inserting the to-be-inserted data into the red-black tree by adopting a corresponding insertion mode according to a matching result. Since each node of the red-black tree stores not only a single data value, but also the initial value and the end value of the range, the storage efficiency is improved, and the waste of the storage space is avoided. And different insertion modes are adopted for different matching results, so that accurate insertion of the to-be-inserted data can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of network security technology, and in particular to a data storage method, device, electronic device and storage medium. Background Art

[0002] The application of range-based data is becoming more and more widespread. In modern gateways and security devices, it is crucial to flexibly and efficiently manage security policies and routing decisions. Modern gateways and security devices need to process a large amount of range-based configuration data (such as Internet Protocol (IP) address ranges, user identity document (ID) ranges and time windows, etc.). These configuration data are used to define access control policies, traffic management rules and time-sensitive operation permissions.

[0003] In the prior art, when storing range-type data, information is usually stored separately for each element in the range, which results in low storage efficiency and requires a lot of storage space. Summary of the invention

[0004] The embodiments of the present application provide a data storage method, device, electronic device and storage medium to improve storage efficiency and save storage space.

[0005] The specific technical solutions provided by the embodiments of this application are as follows:

[0006] In a first aspect, a data storage method is provided, the method comprising:

[0007] Obtain the data to be inserted, the data to be inserted includes: the starting value to be inserted and the ending value to be inserted of the range to be inserted, and the strategy to be inserted;

[0008] Traversing the red-black tree to determine the matching result between the end value of each node of the red-black tree and the end value to be inserted, wherein each node of the red-black tree is used to store the start value and the end value of the corresponding range, and the strategy associated with the range;

[0009] According to the matching results, the corresponding insertion method is used to insert the data to be inserted into the red-black tree.

[0010] Optionally, according to the matching result, a corresponding insertion method is used to insert the data to be inserted into the red-black tree, including:

[0011] If the matching result indicates that there is no matching node in the red-black tree whose end value matches the end value to be inserted, then based on the standard insertion rule, determine the initial insertion point corresponding to the data to be inserted, and insert the data to be inserted into the red-black tree based on the start value to be inserted and the first predecessor node, wherein the first predecessor node is the predecessor node of the initial insertion point;

[0012] If the matching result indicates that there is a matching node in the red-black tree whose end value matches the end value to be inserted, the data to be inserted is inserted into the red-black tree based on the strategy corresponding to the matching node and the strategy to be inserted.

[0013] Through the above method, different insertion methods are adopted for different matching results, so that accurate insertion of the data to be inserted can be achieved.

[0014] Optionally, inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the first predecessor node includes:

[0015] If the starting value to be inserted is equal to the ending value of the first predecessor node plus 1, the first insertion method is adopted to insert the data to be inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node;

[0016] If the starting value to be inserted is greater than or equal to the starting value of the first predecessor node, and less than or equal to the ending value of the first predecessor node, the second insertion method is adopted to insert the data to be inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node.

[0017] Optionally, using a first insertion method, based on the strategy to be inserted and the strategy corresponding to the first predecessor node, inserting the data to be inserted into the red-black tree includes:

[0018] If the strategy to be inserted is the same as the strategy corresponding to the first predecessor node, the position of the data to be inserted in the red-black tree is determined to be the first predecessor node, and the end value of the first predecessor node is updated to the end value to be inserted;

[0019] If the strategy to be inserted is different from the strategy corresponding to the first predecessor node, the data to be inserted is inserted to the initial insertion point.

[0020] Through the above method, the required storage space is effectively reduced by range merging, and the balance of the red-black tree is maintained by local adjustment, making the insertion process simpler and faster, ensuring the high responsiveness and stable operation of the system.

[0021] Optionally, a second insertion method is used to insert the data to be inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node, including:

[0022] If the strategy to be inserted is the same as the strategy corresponding to the first predecessor node, the position of the data to be inserted in the red-black tree is determined to be the first predecessor node, and the red-black tree is not updated;

[0023] If the strategy to be inserted is different from the strategy corresponding to the first predecessor node, a strategy conflict is recorded.

[0024] Through the above method, the nodes overlapping with the range of data to be inserted are found, and the red-black tree is not updated, which optimizes the storage space utilization, reduces the time and resource consumption required for data modification, and improves the overall performance and response speed of the system.

[0025] Optionally, the method further includes:

[0026] If the starting value to be inserted is less than the starting value of the first predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the second predecessor node, wherein the second predecessor node is the predecessor node of the first predecessor node;

[0027] If the starting value to be inserted is greater than or equal to the starting value of the first predecessor node and greater than the ending value of the first predecessor node, the data to be inserted is inserted to the initial insertion point.

[0028] Through the above method, nodes smaller than the initial insertion node are traversed in turn to find nodes that overlap with the starting value to be inserted or are adjacent to the starting value to be inserted, and conflicts and merging problems of the starting value to be inserted are accurately handled. Even if a node matching the ending value to be inserted cannot be found, nodes smaller than the initial insertion node can be traversed to ensure that the insertion of the data to be inserted will not destroy the structure of the red-black tree and the existing data range strategy, thereby ensuring the consistency, integrity and robustness of the data and the robustness of the system.

[0029] Optionally, based on the strategy corresponding to the matching node and the strategy to be inserted, inserting the data to be inserted into the red-black tree includes:

[0030] If the strategy to be inserted is the same as the strategy corresponding to the matching node, and the starting value to be inserted is greater than or equal to the starting value of the matching node, the position of the data to be inserted in the red-black tree is determined to be the matching node, and the red-black tree is not updated;

[0031] If the strategy to be inserted is the same as the strategy corresponding to the matching node, and the starting value to be inserted is less than the starting value of the matching node, then based on the starting value to be inserted and the third predecessor node, the data to be inserted is inserted into the red-black tree, wherein the third predecessor node is the predecessor node of the matching node;

[0032] If the strategy to be inserted is different from the strategy corresponding to the matching node, a strategy conflict is recorded.

[0033] Through the above method, the nodes overlapping with the range of data to be inserted are found, and the red-black tree is not updated, which optimizes the storage space utilization, reduces the time and resource consumption required for data modification, and improves the overall performance and response speed of the system.

[0034] Optionally, based on the starting value to be inserted and the third predecessor node, inserting the data to be inserted into the red-black tree includes:

[0035] If the starting value to be inserted is greater than the ending value of the third predecessor node, the position of the data to be inserted in the red-black tree is determined to be a matching node, and the starting value of the matching node is updated to the starting value to be inserted;

[0036] If the starting value to be inserted is less than or equal to the ending value of the third predecessor node, and the strategy to be inserted is different from the strategy corresponding to the third predecessor node, then a strategy conflict is recorded;

[0037] If the starting value to be inserted is less than or equal to the end value of the third predecessor node, and the strategy to be inserted is the same as the strategy corresponding to the third predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the starting value of the third predecessor node.

[0038] Through the above method, the required storage space is effectively reduced by range merging, and the balance of the red-black tree is maintained by local adjustment, making the insertion process simpler and faster, ensuring the high responsiveness and stable operation of the system.

[0039] Optionally, inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the starting value of the third predecessor node includes:

[0040] If the starting value to be inserted is greater than or equal to the starting value of the third predecessor node, the third predecessor node and the matching node are merged into a new node, the starting value of the new node is the starting value of the third predecessor node, and the ending value of the new node is the ending value of the matching node;

[0041] If the starting value to be inserted is less than the starting value of the third predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the second predecessor node, wherein the fourth predecessor node is the predecessor node of the third predecessor node.

[0042] Through the above method, the required storage space is effectively reduced by range merging, and the balance of the red-black tree is maintained by local adjustment, making the insertion process simpler and faster, ensuring the high responsiveness and stable operation of the system.

[0043] Optionally, according to the matching result, after the data to be inserted is inserted into the red-black tree using a corresponding insertion method, the method further includes:

[0044] Receive a query request, which carries a value to be queried;

[0045] Based on the value to be queried, determine the target node in the red-black tree that meets the preset query conditions;

[0046] If the value to be queried is greater than or equal to the starting value of the target node, the policy corresponding to the target node is used as the policy corresponding to the value to be queried.

[0047] Through the above method, the orderliness and balance of the red-black tree are used to ensure the efficiency of the query operation, making it suitable for environments that require fast access and frequent queries.

[0048] Optionally, based on the value to be queried, determining a target node in the red-black tree that meets a preset query condition includes:

[0049] Traverse the red-black tree, and perform the following operations each time the tree is read: if the end value of the current node is greater than the value to be queried, record the current node as a candidate node, and read the left child node of the current node next time; if the end value of the current node is less than or equal to the value to be queried, read the right child node of the current node next time;

[0050] From the obtained candidate nodes, select the candidate node with the smallest end value as the target node.

[0051] Through the above method, the target node that meets the preset query conditions can be found accurately and quickly, thereby ensuring the efficiency and accuracy of the query.

[0052] In a second aspect, a data storage device is provided, the device comprising:

[0053] An acquisition module is used to acquire data to be inserted, the data to be inserted includes: a starting value to be inserted and an ending value to be inserted of a range to be inserted, and a strategy to be inserted;

[0054] A determination module, used to traverse the red-black tree and determine the matching result between the end value of each node of the red-black tree and the end value to be inserted, wherein each node of the red-black tree is used to store the start value and the end value of the corresponding range, and the strategy associated with the range;

[0055] The insertion module is used to insert the data to be inserted into the red-black tree using the corresponding insertion method according to the matching result.

[0056] Optionally, according to the matching result, when inserting the data to be inserted into the red-black tree using a corresponding insertion method, the insertion module is further used to:

[0057] If the matching result indicates that there is no matching node in the red-black tree whose end value matches the end value to be inserted, then based on the standard insertion rule, determine the initial insertion point corresponding to the data to be inserted, and insert the data to be inserted into the red-black tree based on the start value to be inserted and the first predecessor node, wherein the first predecessor node is the predecessor node of the initial insertion point;

[0058] If the matching result indicates that there is a matching node in the red-black tree whose end value matches the end value to be inserted, the data to be inserted is inserted into the red-black tree based on the strategy corresponding to the matching node and the strategy to be inserted.

[0059] Optionally, when inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the first predecessor node, the insertion module is further used to:

[0060] If the starting value to be inserted is equal to the ending value of the first predecessor node plus 1, the first insertion method is adopted to insert the data to be inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node;

[0061] If the starting value to be inserted is greater than or equal to the starting value of the first predecessor node, and less than or equal to the ending value of the first predecessor node, the second insertion method is adopted to insert the data to be inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node.

[0062] Optionally, when the first insertion mode is adopted and the data to be inserted is inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node, the insertion module is further used to:

[0063] If the strategy to be inserted is the same as the strategy corresponding to the first predecessor node, the position of the data to be inserted in the red-black tree is determined to be the first predecessor node, and the end value of the first predecessor node is updated to the end value to be inserted;

[0064] If the strategy to be inserted is different from the strategy corresponding to the first predecessor node, the data to be inserted is inserted to the initial insertion point.

[0065] Optionally, when the second insertion mode is adopted and the data to be inserted is inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node, the insertion module is further used to:

[0066] If the strategy to be inserted is the same as the strategy corresponding to the first predecessor node, the position of the data to be inserted in the red-black tree is determined to be the first predecessor node, and the red-black tree is not updated;

[0067] If the strategy to be inserted is different from the strategy corresponding to the first predecessor node, a strategy conflict is recorded.

[0068] Optionally, the plug-in module is also used to:

[0069] If the starting value to be inserted is less than the starting value of the first predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the second predecessor node, wherein the second predecessor node is the predecessor node of the first predecessor node;

[0070] If the starting value to be inserted is greater than or equal to the starting value of the first predecessor node and greater than the ending value of the first predecessor node, the data to be inserted is inserted to the initial insertion point.

[0071] Optionally, based on the strategy corresponding to the matching node and the strategy to be inserted, when inserting the data to be inserted into the red-black tree, the insertion module is further used to:

[0072] If the strategy to be inserted is the same as the strategy corresponding to the matching node, and the starting value to be inserted is greater than or equal to the starting value of the matching node, the position of the data to be inserted in the red-black tree is determined to be the matching node, and the red-black tree is not updated;

[0073] If the strategy to be inserted is the same as the strategy corresponding to the matching node, and the starting value to be inserted is less than the starting value of the matching node, then based on the starting value to be inserted and the third predecessor node, the data to be inserted is inserted into the red-black tree, wherein the third predecessor node is the predecessor node of the matching node;

[0074] If the strategy to be inserted is different from the strategy corresponding to the matching node, a strategy conflict is recorded.

[0075] Optionally, when inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the third predecessor node, the insertion module is further used to:

[0076] If the starting value to be inserted is greater than the ending value of the third predecessor node, the position of the data to be inserted in the red-black tree is determined to be a matching node, and the starting value of the matching node is updated to the starting value to be inserted;

[0077] If the starting value to be inserted is less than or equal to the ending value of the third predecessor node, and the strategy to be inserted is different from the strategy corresponding to the third predecessor node, then a strategy conflict is recorded;

[0078] If the starting value to be inserted is less than or equal to the end value of the third predecessor node, and the strategy to be inserted is the same as the strategy corresponding to the third predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the starting value of the third predecessor node.

[0079] Optionally, when inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the starting value of the third predecessor node, the insertion module is further used to:

[0080] If the starting value to be inserted is greater than or equal to the starting value of the third predecessor node, the third predecessor node and the matching node are merged into a new node, the starting value of the new node is the starting value of the third predecessor node, and the ending value of the new node is the ending value of the matching node;

[0081] If the starting value to be inserted is less than the starting value of the third predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the second predecessor node, wherein the fourth predecessor node is the predecessor node of the third predecessor node.

[0082] Optionally, according to the matching result, after the data to be inserted is inserted into the red-black tree using a corresponding insertion method, the device further includes a query module, the query module being used to:

[0083] Receive a query request, which carries a value to be queried;

[0084] Based on the value to be queried, determine the target node in the red-black tree that meets the preset query conditions;

[0085] If the value to be queried is greater than or equal to the starting value of the target node, the policy corresponding to the target node is used as the policy corresponding to the value to be queried.

[0086] Optionally, when determining the target node that meets the preset query condition in the red-black tree based on the value to be queried, the query module is further used to:

[0087] Traverse the red-black tree, and perform the following operations each time the tree is read: if the end value of the current node is greater than the value to be queried, record the current node as a candidate node, and read the left child node of the current node next time; if the end value of the current node is less than or equal to the value to be queried, read the right child node of the current node next time;

[0088] From the obtained candidate nodes, select the candidate node with the smallest end value as the target node.

[0089] In a third aspect, the present application provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any one of the methods described in the first aspect are implemented.

[0090] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of any one of the methods described in the first aspect above.

[0091] In a fifth aspect, the present application provides a computer program product, comprising: a computer program code, when the computer program code is run on a computer, the computer executes any one of the methods described in the first aspect.

[0092] In an embodiment of the present application, the data to be inserted is obtained, and the data to be inserted includes: the starting value to be inserted and the ending value to be inserted of the range to be inserted, and the insertion strategy, and then the red-black tree is traversed to determine the matching result between the ending value of each node of the red-black tree and the ending value to be inserted, wherein each node of the red-black tree is used to store the starting value and the ending value of the corresponding range, and the strategy associated with the range, and finally according to the matching result, the corresponding insertion method is adopted to insert the data to be inserted into the red-black tree. In this way, since each node of the red-black tree stores not only a single data value, but the starting value and the ending value of the range, it is possible to store and process range-type data rather than a single data value, and intuitively express continuous data sets rather than single discrete values, thereby improving storage efficiency and avoiding waste of storage space. At the same time, different insertion methods are adopted for different matching results, so that the data to be inserted can be accurately inserted. BRIEF DESCRIPTION OF THE DRAWINGS

[0093] Figure 1 A schematic diagram of an application scenario in an embodiment of the present application;

[0094] Figure 2 This is a flow chart of a data storage method in an embodiment of the present application;

[0095] Figure 3 This is a schematic diagram of the first process of data insertion in an embodiment of the present application;

[0096] Figure 4 A second flow chart of data insertion in an embodiment of the present application;

[0097] Figure 5 A schematic diagram of the data query process in the embodiment of the present application;

[0098] Figure 6 This is a schematic diagram of the structure of a data storage device in an embodiment of the present application;

[0099] Figure 7 Schematic diagram of the structure of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION

[0100] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. 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 this field without creative work are within the scope of protection of this application.

[0101] Some of the terms used in the embodiments of the present application are explained below to facilitate understanding by those skilled in the art.

[0102] (1) Red Black Tree: It is a self-balancing binary search tree that can insert and delete data with a time complexity of O(logn).

[0103] (2) Range-associated policy: refers to the action corresponding to range data. For example, in the security policy scenario, when the type of range data is an IP address range, the action corresponding to the range data can be release or block.

[0104] (3) Predecessor node: a node that is smaller than the maximum value of the current node. If the current node has a left subtree, the maximum value in the left subtree of the current node is its predecessor.

[0105] The following is a brief introduction to the design concept of the embodiment of the present application:

[0106] At present, the application of range-type data is becoming more and more extensive, for example, it is used in scenarios such as security policies, routing decisions, memory management, and application permission control.

[0107] Specifically, in modern gateways and security devices, it is crucial to flexibly and efficiently manage security policies and routing decisions. Modern gateways and security devices need to process a large amount of range-based configuration data (such as Internet Protocol (IP) address ranges, user identity document (ID) ranges and time windows, etc.), which are used to define access control policies, traffic management rules and time-sensitive operation permissions. For example, an enterprise may need to restrict devices with a specific IP range to access certain servers during working hours, or a social platform may allow users with a certain ID range to post content at specific times.

[0108] In the prior art, when storing range-type data, information is usually stored separately for each element in the range, which has low storage efficiency and requires a lot of storage space. At the same time, the query speed is slow when searching in a large amount of data. In addition, when the stored data needs to be updated, the entire data structure may need to be reconstructed.

[0109] In view of this, in an embodiment of the present application, a data storage method, device, electronic device and storage medium are provided to obtain data to be inserted, the data to be inserted includes: the starting value to be inserted and the ending value to be inserted of the range to be inserted, and the insertion strategy, and then traverse the red-black tree to determine the matching result between the ending value of each node of the red-black tree and the ending value to be inserted, wherein each node of the red-black tree is used to store the starting value and the ending value of the corresponding range, and the strategy associated with the range, and finally according to the matching result, the corresponding insertion method is adopted to insert the data to be inserted into the red-black tree. In this way, since each node of the red-black tree stores not only a single data value, but the starting value and the ending value of the range, it is possible to store and process range-type data instead of a single data value, and intuitively express continuous data sets instead of single discrete values, thereby improving storage efficiency, avoiding waste of storage space, and also improving query speed and query accuracy. By utilizing the orderliness and balance of the red-black tree, fast and accurate range query can be achieved. In addition, different insertion methods are adopted for different matching results, so that the data to be inserted can be accurately inserted.

[0110] The preferred embodiments of the present application are described below in conjunction with the drawings in the specification. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present application, and are not used to limit the present application. In addition, the embodiments of the present application and the features in the embodiments may be combined with each other if there is no conflict.

[0111] like Figure 1 As shown, it is a schematic diagram of an application scenario of an embodiment of the present application. It is a schematic diagram of an application scenario of an embodiment of the present application. The application scenario diagram includes a server 110 and a terminal device 120 (including a terminal device 1201, a terminal device 1202...a terminal device 120n).

[0112] The server 110 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. The terminal device 120 and the server 110 may be directly or indirectly connected via wired or wireless communication, which is not limited in this application.

[0113] The terminal device 120 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart TV, etc., but is not limited thereto.

[0114] It should be noted that Figure 1The figure is only an example. In fact, the number of terminal devices 120 and servers 110 is not limited and is not specifically limited in the embodiments of the present application.

[0115] It should be noted that the above application scenarios are only shown to facilitate understanding of the spirit and principles of the present application, and the implementation methods of the present application are not limited in this regard.

[0116] Based on the above embodiments, see Figure 2 The figure is a flow chart of a data storage method in an embodiment of the present application, which specifically includes:

[0117] Step 20: Get the data to be inserted.

[0118] The data to be inserted includes: a starting value to be inserted and an ending value to be inserted of a range to be inserted, and a strategy to be inserted.

[0119] In addition, it is worth mentioning that the starting value to be inserted defines the beginning of the range to be inserted, which is used to determine the initial boundary of the range to be inserted. The ending value to be inserted defines the end point of the range to be inserted. The starting value to be inserted and the ending value to be inserted together define a continuous range. The number of strategies to be inserted can be one or more, and the range to be inserted is associated with the strategy to be inserted.

[0120] In the embodiment of the present application, the server obtains the data to be inserted in response to the data insertion request sent by the terminal device.

[0121] Step 21: traverse the red-black tree to determine the matching result between the end value of each node of the red-black tree and the end value to be inserted.

[0122] Each node of the red-black tree is used to store the start value and end value of the corresponding range, as well as the strategy associated with the range.

[0123] In addition, it is worth mentioning that the start value defines the beginning of the corresponding range and is used to determine the initial boundary of the corresponding range. The end value defines the end point of the corresponding range and serves as the key to the red-black tree operation. The start value and the end value together define a continuous range. The number of strategies associated with the range can be one or more.

[0124] In an embodiment of the present application, based on the end value to be inserted, starting from the root node of the red-black tree, the red-black tree is traversed to determine whether there is a matching node in the red-black tree whose end value matches the end value to be inserted, wherein the end value of the node of the red-black tree matches the end value to be inserted means that the end value of the node of the red-black tree is equal to the end value to be inserted.

[0125] Step 22: According to the matching result, use the corresponding insertion method to insert the data to be inserted into the red-black tree.

[0126] The matching result is characterized by the fact that there is no matching node in the red-black tree whose end value matches the end value to be inserted, or that there is a matching node in the red-black tree whose end value matches the end value to be inserted.

[0127] Specifically, in the embodiment of the present application, according to the matching result, the corresponding insertion method is adopted to insert the data to be inserted into the red-black tree, which is divided into the following two cases:

[0128] Case 1: The matching result is characterized by the red-black tree not having a matching node whose end value matches the end value to be inserted.

[0129] In an embodiment of the present application, if the matching result indicates that there is no matching node in the red-black tree whose end value matches the end value to be inserted, then based on the standard insertion rule, the initial insertion point corresponding to the data to be inserted is determined, and based on the start value to be inserted and the first predecessor node, the data to be inserted is inserted into the red-black tree.

[0130] Among them, the first predecessor node is the predecessor node of the initial insertion point, that is, the second predecessor node is the node corresponding to the maximum value less than the initial insertion point, and the standard insertion rule is the standard insertion rule of the red-black tree. The standard insertion rule ensures that the balance and sorting rules of the red-black tree are maintained.

[0131] Specifically, in the embodiment of the present application, when inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the first predecessor node, the following operations are specifically performed:

[0132] Step 220A: Determine whether the starting value to be inserted is equal to the ending value of the first predecessor node plus 1. If so, execute step 221A; otherwise, execute step 222A.

[0133] Step 221A: Using the first insertion method, based on the strategy to be inserted and the strategy corresponding to the first predecessor node, insert the data to be inserted into the red-black tree.

[0134] In an embodiment of the present application, if the starting value to be inserted is equal to the ending value of the first predecessor node plus 1, the first insertion method is adopted to insert the data to be inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node.

[0135] Specifically, in the embodiment of the present application, when the first insertion method is adopted, based on the strategy to be inserted and the strategy corresponding to the first predecessor node, the following operations are specifically performed when inserting the data to be inserted into the red-black tree:

[0136] Step 2210A: Determine whether the strategy to be inserted is the same as the strategy corresponding to the first predecessor node. If so, execute step 2211A; otherwise, execute step 2212A.

[0137] Step 2211A: Determine that the position of the data to be inserted in the red-black tree is the first predecessor node, and update the end value of the first predecessor node to the end value to be inserted.

[0138] In an embodiment of the present application, if the strategy to be inserted is the same as the strategy corresponding to the first predecessor node, the position of the data to be inserted in the red-black tree is determined to be the first predecessor node, and the end value of the first predecessor node is updated to the end value to be inserted.

[0139] Among them, if the starting value to be inserted is equal to the end value of the first predecessor node plus 1, and the strategy to be inserted is the same as the strategy corresponding to the first predecessor node, it means that the data to be inserted and the first predecessor node are in adjacent areas with the same strategy, and the data to be inserted and the first predecessor node are range-merged, that is, the end value of the first predecessor node is updated to the end value to be inserted.

[0140] In this way, through range merging, the required storage space is effectively reduced, and local adjustments are made to maintain the balance of the red-black tree, making the insertion process simpler and faster, ensuring the high responsiveness and stable operation of the system.

[0141] Step 2211A: Insert the data to be inserted into the initial insertion point.

[0142] In the embodiment of the present application, if the strategy to be inserted is different from the strategy corresponding to the first predecessor node, the data to be inserted is inserted to the initial insertion point.

[0143] Among them, if the starting value to be inserted is equal to the end value of the first predecessor node plus 1, and the strategy to be inserted is different from the strategy corresponding to the first predecessor node, it means that the data to be inserted and the first predecessor node are adjacent areas with different strategies, and the data to be inserted is inserted to the initial insertion point.

[0144] In an embodiment of the present application, when the data to be inserted is inserted into the initial insertion point, a new node is created at the position of the initial insertion point, with the end value to be inserted as the key value, the start value to be inserted and the insertion strategy as the node data, and then the new node is inserted into the red-black tree using the standard insertion rule of the red-black tree to ensure that the balance and sorting rules of the tree are maintained, and finally the structure of the red-black tree is updated (such as operations such as rotation and recoloring) to maintain the balance characteristics of the red-black tree.

[0145] Step 222A: Determine whether the starting value to be inserted is less than the starting value of the first predecessor node. If so, execute step 223A; otherwise, execute step 224A.

[0146] Step 223A: Based on the starting value to be inserted and the second predecessor node, insert the data to be inserted into the red-black tree.

[0147] The second predecessor node is a predecessor node of the first predecessor node, that is, the second predecessor node is a node corresponding to a maximum value that is smaller than the first predecessor node.

[0148] In the embodiment of the present application, if the starting value to be inserted is less than the starting value of the first predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the second predecessor node. The specific operation of inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the second predecessor node is: taking the second predecessor node as the new first predecessor node, and returning to step 220A.

[0149] In this way, the nodes smaller than the initial insertion node are traversed in turn to find nodes that overlap with the starting value to be inserted or are adjacent to the starting value to be inserted, and the conflicts and merging problems of the starting value to be inserted are accurately handled. Even if no node matching the ending value to be inserted is found, the nodes smaller than the initial insertion node can be traversed to ensure that the insertion of the data to be inserted will not destroy the structure of the red-black tree and the existing data range strategy, thereby ensuring the consistency, integrity and robustness of the data and the robustness of the system.

[0150] Step 224A: Determine whether the starting value to be inserted is less than or equal to the ending value of the first predecessor node. If so, execute step 225A; otherwise, execute step 226A.

[0151] Step 225A: Using the second insertion method, based on the strategy to be inserted and the strategy corresponding to the first predecessor node, insert the data to be inserted into the red-black tree.

[0152] In an embodiment of the present application, if the starting value to be inserted is greater than or equal to the starting value of the first predecessor node, and less than or equal to the ending value of the first predecessor node, the second insertion method is adopted to insert the data to be inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node.

[0153] Specifically, in the embodiment of the present application, when the second insertion method is adopted, based on the strategy to be inserted and the strategy corresponding to the first predecessor node, when inserting the data to be inserted into the red-black tree, the following operations are specifically performed:

[0154] Step 2250A: Determine whether the strategy to be inserted is the same as the strategy corresponding to the first predecessor node. If so, execute step 2251A; otherwise, execute step 2252A.

[0155] Step 2251A: Determine that the position of the data to be inserted in the red-black tree is the first predecessor node, and do not update the red-black tree.

[0156] In the embodiment of the present application, if the strategy to be inserted is the same as the strategy corresponding to the first predecessor node, the position of the data to be inserted in the red-black tree is determined to be the first predecessor node, and the red-black tree is not updated.

[0157] Among them, the starting value to be inserted is greater than or equal to the starting value of the first predecessor node, and less than or equal to the ending value of the first predecessor node, and the strategy to be inserted is the same as the strategy corresponding to the first predecessor node, indicating that the data to be inserted has been covered by the existing configuration of the red-black tree, and there is no need to update the configuration of the red-black tree.

[0158] In this way, the nodes overlapping with the range of data to be inserted are found and the red-black tree is not updated, which optimizes the storage space utilization, reduces the time and resource consumption required for data modification, and improves the overall performance and response speed of the system.

[0159] Optionally, in an embodiment of the present application, after determining that the position of the data to be inserted in the red-black tree is the first predecessor node, the range of the first predecessor node can be adjusted as needed, and this is not limited in the embodiment of the present application.

[0160] For example, if a red-black tree requires a small range of configuration, the starting value of the first predecessor node is modified to the starting value to be inserted.

[0161] Step 2252A: Record policy conflicts.

[0162] In the embodiment of the present application, if the strategy to be inserted is different from the strategy corresponding to the first predecessor node, the strategy conflict is recorded, the data to be inserted is not stored, and the process is terminated.

[0163] Optionally, in an embodiment of the present application, after recording the policy conflict, a prompt message is sent to the terminal device to prompt that there is a policy conflict in the data to be inserted.

[0164] Step 226A: Insert the data to be inserted into the initial insertion point.

[0165] In the embodiment of the present application, if the starting value to be inserted is greater than or equal to the starting value of the first predecessor node and greater than the ending value of the first predecessor node, the data to be inserted is inserted to the initial insertion point.

[0166] In an embodiment of the present application, when the data to be inserted is inserted into the initial insertion point, a new node is created at the position of the initial insertion point, with the end value to be inserted as the key value, the start value to be inserted and the insertion strategy as the node data, and then the new node is inserted into the red-black tree using the standard insertion rule of the red-black tree to ensure that the balance and sorting rules of the tree are maintained, and finally the structure of the red-black tree is updated (such as operations such as rotation and recoloring) to maintain the balance characteristics of the red-black tree.

[0167] Furthermore, after the inserted data is successfully inserted into the red-black tree, the embodiment of the present application can also update the necessary tree information and return the necessary tree information and insertion status information to the terminal device.

[0168] Among them, the necessary tree information may be a node counter and node merge information, etc., which is not limited in the embodiment of the present application. The insertion status information may be insertion success or insertion failure.

[0169] Case 2: The matching result is characterized by the existence of a matching node in the red-black tree whose end value matches the end value to be inserted.

[0170] In an embodiment of the present application, if the matching result indicates that there is a matching node in the red-black tree whose end value matches the end value to be inserted, the data to be inserted is inserted into the red-black tree based on the strategy corresponding to the matching node and the strategy to be inserted.

[0171] Specifically, in the embodiment of the present application, when inserting the data to be inserted into the red-black tree based on the strategy corresponding to the matching node and the strategy to be inserted, the following operations are specifically performed:

[0172] Step 220B: Determine whether the strategy to be inserted is the same as the strategy corresponding to the matching node. If so, execute step 221B; otherwise, execute step 224B.

[0173] Step 221B: Determine whether the starting value to be inserted is greater than or equal to the starting value of the matching node. If so, execute step 222B; otherwise, execute step 223B.

[0174] Step 222B: Determine that the position of the data to be inserted in the red-black tree is a matching node, and do not update the red-black tree.

[0175] In an embodiment of the present application, if the strategy to be inserted is the same as the strategy corresponding to the matching node, and the starting value to be inserted is greater than or equal to the starting value of the matching node, the position of the data to be inserted in the red-black tree is determined to be the matching node, and the red-black tree is not updated.

[0176] Among them, the strategy to be inserted is the same as the strategy corresponding to the matching node, and the starting value to be inserted is greater than or equal to the starting value of the matching node, indicating that the data to be inserted has been covered by the existing configuration of the red-black tree, and there is no need to update the configuration of the red-black tree.

[0177] Optionally, in the embodiment of the present application, after determining that the position of the data to be inserted in the red-black tree is a matching node, the range of the matching node can be adjusted according to needs, and this is not limited in the embodiment of the present application.

[0178] For example, if a red-black tree requires a small range of configuration, the starting value of the matching node is modified to the starting value to be inserted.

[0179] Step 223B: Based on the starting value to be inserted and the third predecessor node, insert the data to be inserted into the red-black tree.

[0180] The third predecessor node is a predecessor node of the matching node, that is, the third predecessor node is a node corresponding to a maximum value that is smaller than the matching node.

[0181] In an embodiment of the present application, if the strategy to be inserted is the same as the strategy corresponding to the matching node, and the starting value to be inserted is less than the start of the matching node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the third predecessor node.

[0182] Specifically, in the embodiment of the present application, when inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the third predecessor node, the following operations are specifically performed:

[0183] Step 2231B: Determine whether the starting value to be inserted is greater than the ending value of the third predecessor node. If so, execute step 2232B; otherwise, execute step 2233B.

[0184] Step 2232B: Determine the position of the data to be inserted in the red-black tree as a matching node, and update the starting value of the matching node to the starting value to be inserted

[0185] In an embodiment of the present application, it is determined whether the starting value to be inserted is greater than the ending value of the third predecessor node. If the starting value to be inserted is greater than the ending value of the third predecessor node, the position of the data to be inserted in the red-black tree is determined to be a matching node, and the starting value of the matching node is updated to the starting value to be inserted.

[0186] Among them, the starting value to be inserted is greater than the ending value of the third predecessor node, which means that the data to be inserted does not conflict with the left range of the matching node. The data to be inserted and the matching node are range-merged, that is, the starting value of the matching node is updated to the starting value to be inserted.

[0187] In this way, through range merging, the required storage space is effectively reduced, and local adjustments are made to maintain the balance of the red-black tree, making the insertion process simpler and faster, ensuring the high responsiveness and stable operation of the system.

[0188] Step 2233B: Determine whether the strategy to be inserted is different from the strategy corresponding to the third predecessor node. If so, execute step 2234B; otherwise, execute step 2235B.

[0189] Step 2234B: Record policy conflicts.

[0190] In an embodiment of the present application, if the starting value to be inserted is less than or equal to the ending value of the third predecessor node, and the strategy to be inserted is different from the strategy corresponding to the third predecessor node, the strategy conflict is recorded, the data to be inserted is not stored, and the process terminates.

[0191] Optionally, in an embodiment of the present application, after recording the policy conflict, a prompt message is sent to the terminal device to prompt that there is a policy conflict in the data to be inserted.

[0192] Step 2235B: Based on the starting value to be inserted and the starting value of the third predecessor node, insert the data to be inserted into the red-black tree.

[0193] In an embodiment of the present application, if the starting value to be inserted is less than or equal to the ending value of the third predecessor node, and the strategy to be inserted is the same as the strategy corresponding to the third predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the starting value of the third predecessor node.

[0194] Specifically, in the embodiment of the present application, based on the starting value to be inserted and the starting value of the third predecessor node, the data to be inserted is inserted into the red-black tree, and the following operations are specifically performed:

[0195] Step 2235-1B: Determine whether the starting value to be inserted is greater than or equal to the starting value of the third predecessor node. If so, execute step 2235-2B; otherwise, execute step 2235-3B.

[0196] Step 2235-2B: Merge the third predecessor node and the matching node into a new node

[0197] The starting value of the new node is the starting value of the third predecessor node, and the ending value of the new node is the ending value of the matching node.

[0198] In the embodiment of the present application, it is determined whether the starting value to be inserted is greater than or equal to the starting value of the third predecessor node. If the starting value to be inserted is greater than or equal to the starting value of the third predecessor node, the third predecessor node and the matching node are merged into a new node. The specific operation of merging the third predecessor node and the matching node into a new node is: deleting the third predecessor node, at which time the predecessor node of the matching node is updated to the predecessor node of the third predecessor node, and the starting value of the matching node is modified to the starting value of the third predecessor node.

[0199] In this way, through range merging, the required storage space is effectively reduced, and local adjustments are made to maintain the balance of the red-black tree, making the insertion process simpler and faster, ensuring the high responsiveness and stable operation of the system.

[0200] Step 2235-3B: Based on the starting value to be inserted and the second predecessor node, insert the data to be inserted into the red-black tree.

[0201] The fourth predecessor node is a predecessor node of the third predecessor node, that is, the fourth predecessor node is a node corresponding to a maximum value that is smaller than the third predecessor node.

[0202] In the embodiment of the present application, it is determined whether the starting value to be inserted is greater than or equal to the starting value of the third predecessor node. If the starting value to be inserted is less than the starting value of the third predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the second predecessor node. The specific operation of inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the second predecessor node is: using the fourth predecessor node as the new third predecessor node, returning to step 2231B, and executing the process from step 2231B to step 2235B.

[0203] Step 224B: Record policy conflicts.

[0204] In the embodiment of the present application, it is determined whether the strategy to be inserted is the same as the strategy corresponding to the matching node. If the strategy to be inserted is different from the strategy corresponding to the matching node, the strategy conflict is recorded, the data to be inserted is not stored, and the process is terminated.

[0205] Optionally, in an embodiment of the present application, after recording the policy conflict, a prompt message is sent to the terminal device to prompt that there is a policy conflict in the data to be inserted.

[0206] In this way, data consistency is ensured through strict strategies and range matching. The properties of red-black trees are used to maintain the balance of the data structure and efficiently handle insertion conflicts.

[0207] Based on the above embodiments, see Figure 3 As shown, it is a first flow diagram of data insertion when there is no matching node whose end value matches the end value to be inserted in the red-black tree in the embodiment of the present application, which specifically includes:

[0208] Step 30: Determine whether the starting value to be inserted is equal to the ending value of the first predecessor node plus 1. If so, execute step 31; otherwise, execute step 34.

[0209] In an embodiment of the present application, when there is no matching node in the red-black tree whose end value matches the end value to be inserted, it is determined whether the start value to be inserted is equal to the end value of the first predecessor node plus 1.

[0210] The data to be inserted includes: the starting value to be inserted and the ending value to be inserted of the range to be inserted, and the strategy to be inserted. The first predecessor node is the predecessor node of the initial insertion point.

[0211] Step 31: Determine whether the strategy to be inserted is the same as the strategy corresponding to the first predecessor node. If so, execute step 32; otherwise, execute step 33.

[0212] Step 32: Determine that the position of the data to be inserted in the red-black tree is the first predecessor node, and update the end value of the first predecessor node to the end value to be inserted.

[0213] Step 33: Insert the data to be inserted into the initial insertion point.

[0214] Step 34: Determine whether the starting value to be inserted is less than the starting value of the first predecessor node. If so, execute step 35; otherwise, execute step 36.

[0215] Step 35: Use the predecessor node of the first predecessor node as a new first predecessor node.

[0216] In the embodiment of the present application, after the predecessor node of the first predecessor node is used as the new first predecessor node, the process returns to step 30 .

[0217] Step 36: Determine whether the starting value to be inserted is less than or equal to the ending value of the first predecessor node. If so, execute step 37; otherwise, execute step 33.

[0218] Step 37: Determine whether the strategy to be inserted is the same as the strategy corresponding to the first predecessor node. If so, execute step 38; otherwise, execute step 39.

[0219] Step 38: Determine the position of the data to be inserted in the red-black tree as the first predecessor node, and do not update the red-black tree.

[0220] Step 39: Log policy violations.

[0221] Based on the above embodiments, see Figure 4 As shown, it is a second flow diagram of data insertion when there is a matching node whose end value matches the end value to be inserted in the red-black tree in the embodiment of the present application, which specifically includes:

[0222] Step 40: Determine whether the strategy to be inserted is different from the strategy corresponding to the matching node. If so, execute step 41; otherwise, execute step 42.

[0223] In the embodiment of the present application, when there is a matching node in the red-black tree whose end value matches the end value to be inserted, it is determined whether the strategy to be inserted is different from the strategy corresponding to the matching node.

[0224] The data to be inserted includes: a starting value to be inserted and an ending value to be inserted of a range to be inserted, and a strategy to be inserted.

[0225] Step 41: Log policy conflicts.

[0226] Step 42: Determine whether the starting value to be inserted is greater than or equal to the starting value of the matching node. If so, execute step 43; otherwise, execute step 44.

[0227] Step 43: Determine that the position of the data to be inserted in the red-black tree is a matching node, and do not update the red-black tree.

[0228] Step 44: Determine whether the starting value to be inserted is greater than the ending value of the third predecessor node. If so, execute step 45; otherwise, execute step 46.

[0229] The third predecessor node is the predecessor node of the matching node.

[0230] Step 45: Determine the position of the data to be inserted in the red-black tree as a matching node, and update the starting value of the matching node to the starting value to be inserted.

[0231] Step 46: Determine whether the strategy to be inserted is different from the strategy corresponding to the third predecessor node. If so, execute step 41; otherwise, execute step 47.

[0232] Step 47: Determine whether the starting value to be inserted is greater than or equal to the starting value of the third predecessor node. If so, execute step 48; otherwise, execute step 49.

[0233] Step 48: Merge the third predecessor node and the matching node into a new node.

[0234] The starting value of the new node is the starting value of the third predecessor node, and the ending value of the new node is the ending value of the matching node.

[0235] Step 49: Use the predecessor node of the third predecessor node as a new third predecessor node.

[0236] In the embodiment of the present application, after the predecessor node of the third predecessor node is used as the new third predecessor node, the process returns to step 44 .

[0237] Based on the above embodiments, a data query method is also provided in the embodiments of the present application. Figure 5 The figure is a schematic diagram of the process of data query in the embodiment of the present application, which specifically includes:

[0238] Step 50: Receive a query request.

[0239] The query request carries the value to be queried.

[0240] In the embodiment of the present application, the server obtains the value to be queried in response to the query request sent by the terminal device.

[0241] Step 51: Based on the value to be queried, determine the target node in the red-black tree that meets the preset query condition.

[0242] In the embodiment of the present application, based on the value to be queried, the red-black tree is traversed to determine the target node in the red-black tree that meets the preset query condition.

[0243] The target node that meets the preset query condition is: the node whose end value is greater than the value to be queried and whose end value is the smallest.

[0244] Specifically, in the embodiment of the present application, when determining the target node that meets the preset query condition in the red-black tree based on the value to be queried, the following operations are specifically performed:

[0245] Step 510: traverse the red-black tree, wherein each time the tree is read, the following operations are performed: if the end value of the current node is greater than the value to be queried, the current node is recorded as a candidate node, and the left child node of the current node is read next time; if the end value of the current node is less than or equal to the value to be queried, the right child node of the current node is read next time.

[0246] Among them, the current node is the node read this time.

[0247] In an embodiment of the present application, starting from the root node of the red-black tree, the red-black tree is traversed, wherein each time it is read, the following operations are performed: determine whether the end value of the current node is greater than the value to be queried; if so, record the current node as a candidate node, and read the left child node of the current node next time; otherwise, read the right child node of the current node next time.

[0248] In addition, it is worth noting that in the embodiment of the present application, when the left child node of the current node is read next time, if the current node has a left child node, the next read is performed, and if the current node does not have a left child node, the traversal is stopped. When the right child node of the current node is read next time, if the current node has a right child node, the next read is performed, and if the current node does not have a right child node, the traversal is stopped.

[0249] Step 511: From among the obtained candidate nodes, select the candidate node with the smallest end value as the target node.

[0250] In the embodiment of the present application, the end values ​​of the obtained candidate nodes are compared, and the candidate node with the smallest end value is selected as the target node.

[0251] In addition, it is worth noting that in the embodiment of the present application, if there is no candidate node, it is determined that the policy corresponding to the queried value is not found, and a prompt message indicating that it is not found is returned to the terminal device.

[0252] In this way, the target node that meets the preset query conditions can be found accurately and quickly, thereby ensuring the efficiency and accuracy of the query.

[0253] Step 52: Determine whether the value to be queried is greater than or equal to the starting value of the target node. If so, execute step 53; otherwise, execute step 54.

[0254] Step 53: Use the policy corresponding to the target node as the policy corresponding to the value to be queried.

[0255] In an embodiment of the present application, if the value to be queried is greater than or equal to the starting value of the target node, the policy corresponding to the target node is used as the policy corresponding to the value to be queried. After obtaining the policy corresponding to the value to be queried, the query is stopped and the policy details of the policy corresponding to the value to be queried are returned to the terminal device.

[0256] In this way, the orderliness and balance of the red-black tree ensure the efficiency of the query operation, making it suitable for environments that require fast access and frequent queries.

[0257] Step 54: It is determined that no policy corresponding to the value to be queried is found.

[0258] In the embodiment of the present application, if the value to be queried is less than the starting value of the target node, it is determined that the policy corresponding to the value to be queried is not found, and a prompt message indicating that it is not found is returned to the terminal device.

[0259] Based on the same inventive concept, the present application embodiment provides a data storage device, please refer to Figure 6 , the device comprises:

[0260] The acquisition module 601 is used to acquire the data to be inserted, where the data to be inserted includes: a starting value to be inserted and an ending value to be inserted of a range to be inserted, and a strategy to be inserted;

[0261] A determination module 602 is used to traverse the red-black tree and determine the matching result between the end value of each node of the red-black tree and the end value to be inserted, wherein each node of the red-black tree is used to store the start value and the end value of the corresponding range, and the strategy associated with the range;

[0262] The insertion module 603 is used to insert the data to be inserted into the red-black tree using a corresponding insertion method according to the matching result.

[0263] Optionally, according to the matching result, when inserting the data to be inserted into the red-black tree using a corresponding insertion method, the insertion module 603 is further used to:

[0264] If the matching result indicates that there is no matching node in the red-black tree whose end value matches the end value to be inserted, then based on the standard insertion rule, determine the initial insertion point corresponding to the data to be inserted, and insert the data to be inserted into the red-black tree based on the start value to be inserted and the first predecessor node, wherein the first predecessor node is the predecessor node of the initial insertion point;

[0265] If the matching result indicates that there is a matching node in the red-black tree whose end value matches the end value to be inserted, the data to be inserted is inserted into the red-black tree based on the strategy corresponding to the matching node and the strategy to be inserted.

[0266] Optionally, when inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the first predecessor node, the inserting module 603 is further used to:

[0267] If the starting value to be inserted is equal to the ending value of the first predecessor node plus 1, the first insertion method is adopted to insert the data to be inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node;

[0268] If the starting value to be inserted is greater than or equal to the starting value of the first predecessor node, and less than or equal to the ending value of the first predecessor node, the second insertion method is adopted to insert the data to be inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node.

[0269] Optionally, when the first insertion mode is adopted and the data to be inserted is inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node, the insertion module 603 is further used to:

[0270] If the strategy to be inserted is the same as the strategy corresponding to the first predecessor node, the position of the data to be inserted in the red-black tree is determined to be the first predecessor node, and the end value of the first predecessor node is updated to the end value to be inserted;

[0271] If the strategy to be inserted is different from the strategy corresponding to the first predecessor node, the data to be inserted is inserted to the initial insertion point.

[0272] Optionally, when the second insertion mode is adopted and the data to be inserted is inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node, the insertion module 603 is further used to:

[0273] If the strategy to be inserted is the same as the strategy corresponding to the first predecessor node, the position of the data to be inserted in the red-black tree is determined to be the first predecessor node, and the red-black tree is not updated;

[0274] If the strategy to be inserted is different from the strategy corresponding to the first predecessor node, a strategy conflict is recorded.

[0275] Optionally, the insertion module 603 is further used for:

[0276] If the starting value to be inserted is less than the starting value of the first predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the second predecessor node, wherein the second predecessor node is the predecessor node of the first predecessor node;

[0277] If the starting value to be inserted is greater than or equal to the starting value of the first predecessor node and greater than the ending value of the first predecessor node, the data to be inserted is inserted to the initial insertion point.

[0278] Optionally, based on the strategy corresponding to the matching node and the strategy to be inserted, when inserting the data to be inserted into the red-black tree, the insertion module 603 is further used to:

[0279] If the strategy to be inserted is the same as the strategy corresponding to the matching node, and the starting value to be inserted is greater than or equal to the starting value of the matching node, the position of the data to be inserted in the red-black tree is determined to be the matching node, and the red-black tree is not updated;

[0280] If the strategy to be inserted is the same as the strategy corresponding to the matching node, and the starting value to be inserted is less than the starting value of the matching node, then based on the starting value to be inserted and the third predecessor node, the data to be inserted is inserted into the red-black tree, wherein the third predecessor node is the predecessor node of the matching node;

[0281] If the strategy to be inserted is different from the strategy corresponding to the matching node, a strategy conflict is recorded.

[0282] Optionally, when inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the third predecessor node, the inserting module 603 is further used to:

[0283] If the starting value to be inserted is greater than the ending value of the third predecessor node, the position of the data to be inserted in the red-black tree is determined to be a matching node, and the starting value of the matching node is updated to the starting value to be inserted;

[0284] If the starting value to be inserted is less than or equal to the ending value of the third predecessor node, and the strategy to be inserted is different from the strategy corresponding to the third predecessor node, then a strategy conflict is recorded;

[0285] If the starting value to be inserted is less than or equal to the end value of the third predecessor node, and the strategy to be inserted is the same as the strategy corresponding to the third predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the starting value of the third predecessor node.

[0286] Optionally, when inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the starting value of the third predecessor node, the inserting module 603 is further used to:

[0287] If the starting value to be inserted is greater than or equal to the starting value of the third predecessor node, the third predecessor node and the matching node are merged into a new node, the starting value of the new node is the starting value of the third predecessor node, and the ending value of the new node is the ending value of the matching node;

[0288] If the starting value to be inserted is less than the starting value of the third predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the second predecessor node, wherein the fourth predecessor node is the predecessor node of the third predecessor node.

[0289] Optionally, according to the matching result, after the data to be inserted is inserted into the red-black tree using a corresponding insertion method, the device further includes a query module 604, which is used to:

[0290] Receive a query request, which carries a value to be queried;

[0291] Based on the value to be queried, determine the target node in the red-black tree that meets the preset query conditions;

[0292] If the value to be queried is greater than or equal to the starting value of the target node, the policy corresponding to the target node is used as the policy corresponding to the value to be queried.

[0293] Optionally, when determining the target node that meets the preset query condition in the red-black tree based on the value to be queried, the query module 604 is further used to:

[0294] Traverse the red-black tree, and perform the following operations each time the tree is read: if the end value of the current node is greater than the value to be queried, record the current node as a candidate node, and read the left child node of the current node next time; if the end value of the current node is less than or equal to the value to be queried, read the right child node of the current node next time;

[0295] From the obtained candidate nodes, select the candidate node with the smallest end value as the target node.

[0296] Based on the above embodiments, see Figure 7 Shown is a schematic diagram of the structure of an electronic device in an embodiment of the present application.

[0297] An embodiment of the present application provides an electronic device, which may include a processor 710 (Center Processing Unit, CPU), a memory 720, an input device 730 and an output device 740, etc. The input device 730 may include a keyboard, a mouse, a touch screen, etc., and the output device 740 may include a display device, such as a liquid crystal display (Liquid Crystal Display, LCD), a cathode ray tube (Cathode Ray Tube, CRT), etc.

[0298] The memory 720 may include a read-only memory (ROM) and a random access memory (RAM), and provides the processor 710 with program instructions and data stored in the memory 720. In the embodiment of the present application, the memory 720 may be used to store a program of any data storage method in the embodiment of the present application.

[0299] The processor 710 calls the program instructions stored in the memory 720, and the processor 710 is used to execute any data storage method in the embodiments of the present application according to the obtained program instructions.

[0300] Based on the above embodiments, in an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the data storage method in any of the above method embodiments is implemented.

[0301] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0302] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0303] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0304] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0305] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A data storage method, characterized in that: include: Acquire the data to be inserted, wherein the data to be inserted includes: a starting value to be inserted and an ending value to be inserted of a range to be inserted, and a strategy to be inserted; Traversing a red-black tree to determine a matching result between an end value of each node of the red-black tree and the end value to be inserted, wherein each node of the red-black tree is used to store a start value and an end value of a corresponding range, and a strategy associated with the range; According to the matching result, the data to be inserted is inserted into the red-black tree using a corresponding insertion method.

2. The method according to claim 1, characterized in that The method of inserting the data to be inserted into the red-black tree using a corresponding insertion method according to the matching result includes: If the matching result indicates that there is no matching node in the red-black tree whose end value matches the end value to be inserted, then based on the standard insertion rule, determine the initial insertion point corresponding to the data to be inserted, and insert the data to be inserted into the red-black tree based on the start value to be inserted and the first predecessor node, wherein the first predecessor node is the predecessor node of the initial insertion point; If the matching result indicates that there is a matching node in the red-black tree whose end value matches the end value to be inserted, the data to be inserted is inserted into the red-black tree based on the strategy corresponding to the matching node and the strategy to be inserted.

3. The method according to claim 2, characterized in that The method of inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the first predecessor node includes: If the starting value to be inserted is equal to the ending value of the first predecessor node plus 1, the first insertion method is adopted to insert the data to be inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node; If the starting value to be inserted is greater than or equal to the starting value of the first predecessor node, and less than or equal to the ending value of the first predecessor node, the second insertion method is adopted to insert the data to be inserted into the red-black tree based on the strategy to be inserted and the strategy corresponding to the first predecessor node.

4. The method according to claim 3, characterized in that The adopting the first insertion mode, based on the to-be-inserted strategy and the strategy corresponding to the first predecessor node, inserting the to-be-inserted data into the red-black tree includes: If the strategy to be inserted is the same as the strategy corresponding to the first predecessor node, determining the position of the data to be inserted in the red-black tree as the first predecessor node, and updating the end value of the first predecessor node to the end value to be inserted; If the strategy to be inserted is different from the strategy corresponding to the first predecessor node, the data to be inserted is inserted into the initial insertion point.

5. The method according to claim 3, characterized in that The adopting the second insertion mode, based on the to-be-inserted strategy and the strategy corresponding to the first predecessor node, inserting the to-be-inserted data into the red-black tree, includes: If the strategy to be inserted is the same as the strategy corresponding to the first predecessor node, determining the position of the data to be inserted in the red-black tree as the first predecessor node, and not updating the red-black tree; If the strategy to be inserted is different from the strategy corresponding to the first predecessor node, a strategy conflict is recorded.

6. The method according to claim 3, characterized in that The method further comprises: If the starting value to be inserted is less than the starting value of the first predecessor node, inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the second predecessor node, wherein the second predecessor node is the predecessor node of the first predecessor node; If the starting value to be inserted is greater than or equal to the starting value of the first predecessor node and greater than the ending value of the first predecessor node, the data to be inserted is inserted to the initial insertion point.

7. The method according to claim 2, characterized in that The inserting the data to be inserted into the red-black tree based on the strategy corresponding to the matching node and the strategy to be inserted includes: If the strategy to be inserted is the same as the strategy corresponding to the matching node, and the starting value to be inserted is greater than or equal to the starting value of the matching node, then the position of the data to be inserted in the red-black tree is determined to be the matching node, and the red-black tree is not updated; If the strategy to be inserted is the same as the strategy corresponding to the matching node, and the starting value to be inserted is less than the starting value of the matching node, then based on the starting value to be inserted and the third predecessor node, the data to be inserted is inserted into the red-black tree, wherein the third predecessor node is the predecessor node of the matching node; If the to-be-inserted policy is different from the policy corresponding to the matching node, a policy conflict is recorded.

8. The method according to claim 7, characterized in that The method of inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the third predecessor node includes: If the starting value to be inserted is greater than the ending value of the third predecessor node, determining the position of the data to be inserted in the red-black tree as the matching node, and updating the starting value of the matching node to the starting value to be inserted; If the starting value to be inserted is less than or equal to the ending value of the third predecessor node, and the strategy to be inserted is different from the strategy corresponding to the third predecessor node, then a strategy conflict is recorded; If the starting value to be inserted is less than or equal to the ending value of the third predecessor node, and the strategy to be inserted is the same as the strategy corresponding to the third predecessor node, then based on the starting value to be inserted and the starting value of the third predecessor node, the data to be inserted is inserted into the red-black tree.

9. The method according to claim 8, characterized in that The inserting the data to be inserted into the red-black tree based on the starting value to be inserted and the starting value of the third predecessor node includes: If the starting value to be inserted is greater than or equal to the starting value of the third predecessor node, the third predecessor node and the matching node are merged into a new node, the starting value of the new node is the starting value of the third predecessor node, and the ending value of the new node is the ending value of the matching node; If the starting value to be inserted is less than the starting value of the third predecessor node, the data to be inserted is inserted into the red-black tree based on the starting value to be inserted and the second predecessor node, wherein the fourth predecessor node is the predecessor node of the third predecessor node.

10. The method according to claim 1, characterized in that After inserting the data to be inserted into the red-black tree using a corresponding insertion method according to the matching result, the method further includes: receiving a query request, wherein the query request carries a value to be queried; Based on the value to be queried, determining a target node in the red-black tree that meets a preset query condition; If the value to be queried is greater than or equal to the starting value of the target node, the policy corresponding to the target node is used as the policy corresponding to the value to be queried.

11. The method according to claim 10, characterized in that The step of determining a target node in the red-black tree that meets a preset query condition based on the value to be queried includes: Traversing the red-black tree, wherein each time the tree is read, the following operations are performed: if the end value of the current node is greater than the value to be queried, the current node is recorded as a candidate node, and the left child node of the current node is read next time; if the end value of the current node is less than or equal to the value to be queried, the right child node of the current node is read next time; From the obtained candidate nodes, select the candidate node with the smallest end value as the target node.

12. A data storage device, characterized in that: include: An acquisition module, used for acquiring data to be inserted, wherein the data to be inserted includes: a starting value to be inserted and an ending value to be inserted of a range to be inserted, and a strategy to be inserted; A determination module, used to traverse a red-black tree and determine a matching result between an end value of each node of the red-black tree and the end value to be inserted, wherein each node of the red-black tree is used to store a start value and an end value of a corresponding range, and a strategy associated with the range; An insertion module is used to insert the data to be inserted into the red-black tree using a corresponding insertion method according to the matching result.

13. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the method according to any one of claims 1 to 11 are implemented.

14. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.

15. A computer program product, characterized in that The computer program product comprises: a computer program code, and when the computer program code is run on a computer, the computer is enabled to execute the method according to any one of claims 1 to 11.

Citation Information

Cited By

  • Security policy division method and device, storage medium and computing equipment

    CN121567468A