A data relationship storage method, device, system and readable storage medium
By using relational nodes to store arrays in the data relational storage system and determining index values based on the relationship type, the problems of data redundancy and maintenance difficulties in the prior art are solved, and more efficient data storage and query are achieved.
Patent Information
- Application Number
- CN202411764257.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2044-12-03
AI Technical Summary
The prior art causes data redundancy and maintenance difficulties when storing and querying relationship networks, especially when paired or interrelated storage between roles.
By introducing a relational node storage array in the data relational storage system and determining the target index value based on the relationship type (peer relationship or one-to-many relationship), the storage and query process of the relation node are optimized.
It effectively reduces the redundant data of the relationship, improves the flexibility and neatness of data storage, and simplifies the subsequent query and maintenance process.
Smart Images

Figure CN119248793B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data storage, and in particular to a data relationship storage method, device, system and readable storage medium. Background Art
[0002] In some project requirements, computers need to store and query relationship networks, such as relationships between roles, such as friends, colleagues, teachers and students. Existing solutions for storing relationships between roles all use certain data as a target to obtain relationships, because many relationships are usually paired or mutual. For example, if A has a friend relationship with B, then B must have a friend relationship with A. At this time, A needs to store a copy of B's data, and B also needs to store a copy of A's data, which leads to data redundancy and difficulty in maintenance. Summary of the invention
[0003] In view of this, the present invention provides a data relationship storage method, device, system and readable storage medium to solve the problem of storing paired or mutual data with a certain data as the target, resulting in data redundancy and difficulty in maintenance.
[0004] In a first aspect, the present invention provides a data relationship storage method, which is applied to a data relationship storage system, wherein the data relationship storage system includes at least a relationship node storage array, and the method includes: in response to adding a relationship node of a first object and a second object, determining a target index value of the relationship node stored in the relationship node storage array, wherein the relationship node includes at least the first object, the second object, the previous relationship node index value of the first object, and the previous relationship node index value of the second object; obtaining the first index value and the second index value of the first object and the second object of the current record, which are respectively stored in the relationship node storage array, and updating the first index value and the second index value to the previous relationship node index value of the first object and the previous relationship node index value of the second object in the relationship node; updating the first index value and the second index value to the target index values respectively; and storing the updated relationship node in the relationship node storage array based on the target index value.
[0005] The data relationship storage method provided in the present embodiment determines, in response to adding a relationship node between a first object and a second object, a target index value of the relationship node stored in a relationship node storage array, obtains the first index value and the second index value of the first object and the second object of the current record that are most recently stored in the relationship node storage array, respectively, and updates the first index value and the second index value to the previous relationship node index value of the first object and the previous relationship node index value of the second object in the relationship node, respectively, and then updates the first index value and the second index value to the target index value, respectively, and finally stores the updated relationship node in the relationship node storage array based on the target index value, thereby realizing a method of storing relationship nodes through data structures and reducing redundant data of the relationship.
[0006] In an optional embodiment, the relationship node storage array includes a peer relationship array and a one-to-many relationship array, and the relationship node also includes the relationship type between the first object and the second object. Before determining the target index value of the relationship node stored in the relationship node storage array, the method also includes: judging whether the relationship type between the first object and the second object is a peer relationship type or a one-to-many relationship type; if the relationship type between the first object and the second object is a peer relationship type, determining the target index value of the relationship node stored in the peer relationship array; if the relationship type between the first object and the second object is a one-to-many relationship type, determining the target index value of the relationship node stored in the one-to-many relationship array.
[0007] The present invention is based on the relationship type between objects, which is divided into peer-to-peer relationship and one-to-many relationship. Different relationship types have their corresponding relationship storage arrays, which can improve the flexibility and neatness of array storage. When searching for the target relationship type in the future, it can be queried from its corresponding relationship storage array, which is faster.
[0008] In an optional embodiment, the method further includes: in response to querying the target relationship type of the target object, obtaining the latest index value to be queried of the target object currently recorded in the relationship node storage array; obtaining the relationship node corresponding to the target object stored at the index value to be queried, and determining whether the relationship type recorded in the relationship node corresponding to the target object is the target relationship type; if the relationship type recorded in the relationship node corresponding to the target object is the target relationship type, then recording the index value of the relationship node corresponding to the target object stored in the relationship node storage array; and determining the index value of the previous relationship node of the target object in the relationship node corresponding to the target object; updating the index value of the previous relationship node to the index value to be queried, and returning to execute the step of obtaining the relationship node corresponding to the target object stored at the index value to be queried, until it is determined that the index value of the previous relationship node represents the relationship node where the target object is stored for the first time, and obtaining all index values of the target relationship type of the target object in the relationship node storage array.
[0009] In response to the target relationship type of the target object being queried, the present invention can pre-acquire the target object's latest index value to be queried stored in the relationship node storage array, and query forward in sequence based on the previous relationship node index value recorded in the relationship node until the next relationship node is empty, thereby realizing convenient query of relationship nodes through index value query and performing subsequent processing.
[0010] In an optional embodiment, the method further includes: in response to querying the relationship type between the first target object and the second target object, obtaining the latest index value to be queried of the first object or the second object of the current record stored in the peer relationship array and the one-to-many relationship array respectively; obtaining the relationship node stored at the index value to be queried corresponding to the first object or the second object from the peer relationship array and the one-to-many relationship array respectively, and judging whether the relationship node is the relationship node of the first target object and the second target object; if the relationship node is the relationship node of the first target object and the second target object, recording the relationship type of the first object and the second object in the relationship node; determining the index value of the previous relationship node of the first target object or the second target object in the relationship node; updating the index value of the previous relationship node to the index value to be queried, returning to execute the step of obtaining the relationship node stored at the index value to be queried corresponding to the first object or the second object, until the index value of the previous relationship node of the first target object or the second target object is represented as the relationship node of the first storage of the first target object or the second target object, and obtaining all relationship types corresponding to the first target object and the second target object.
[0011] In an optional embodiment, the method further includes: in response to deleting the target relationship type of the target object, determining whether the target relationship type is a peer-to-peer relationship type or a one-to-many relationship type; if the target relationship type is a peer-to-peer relationship type, or the target relationship type is a one-to-many relationship type, and the target object is a unilateral object, obtaining the index value of the relationship node corresponding to the target object stored in the peer-to-peer relationship array or the one-to-many relationship array, and the index value of the previous relationship node corresponding to the target object and another object recorded in the relationship node corresponding to the target object, the other object representing at least one object other than the target object in the relationship node corresponding to the target object; the index value of the previous relationship node of the target object recorded in the query is the index value of the previous relationship node corresponding to the target object The method comprises the following steps: updating the index value of the previous relationship node of the target object recorded in the first node to be updated to the index value of the previous relationship node of the target object recorded in the relationship node corresponding to the target object, and updating the index value of the previous relationship node of the other object recorded in the second node to be updated to the index value of the previous relationship node of the other object recorded in the relationship node corresponding to the target object; removing the relationship node corresponding to the target object from the peer-to-peer relationship array or the one-to-many relationship array.
[0012] The present invention realizes the removal of the relationship node by changing the index value of the previous relationship node recorded in the relationship node, and the solution is more convenient and simple.
[0013] In an optional embodiment, the method also includes: if the target object is a multi-party object, removing the target object from the relationship node corresponding to the target object; obtaining the index value of the relationship node corresponding to the target object stored in the one-to-many relationship array, and the index value of the previous relationship node of the target object recorded in the relationship node corresponding to the target object; querying a third node to be updated whose index value of the previous relationship node of the target object recorded is the index value of the relationship node corresponding to the target object stored in the one-to-many relationship array; updating the index value of the previous relationship node of the target object recorded in the third node to be updated to the index value of the previous relationship node of the target object recorded in the relationship node corresponding to the target object.
[0014] In an optional embodiment, the data storage relationship storage system also includes a relationship node storage linked list, and the method also includes: in response to converting the relationship node storage array into a relationship node storage linked list, using each relationship node in the relationship node storage array as a data element in the relationship node storage linked list; based on the index value of each relationship node stored in the relationship node storage array, and the index value of the previous relationship node of all objects recorded in each relationship node, converting into pointers connecting each data element to obtain a relationship node storage linked list.
[0015] In a second aspect, the present invention provides a data relationship storage device, which is applied to a data relationship storage system, wherein the data relationship storage system at least includes a relationship node storage array, and the device includes: an index determination module, which is used to determine the target index value of the relationship node stored in the relationship node storage array in response to adding a relationship node of a first object and a second object, wherein the relationship node at least includes the first object, the second object, the previous relationship node index value of the first object and the previous relationship node index value of the second object; a relationship node update module, which is used to obtain the first index value and the second index value of the first object and the second object of the current record, which are respectively stored in the relationship node storage array, and update the first index value and the second index value to the previous relationship node index value of the first object and the previous relationship node index value of the second object in the relationship node; an index value update module, which is used to update the first index value and the second index value to the target index value respectively; and a relationship node storage module, which is used to store the updated relationship node in the relationship node storage array based on the target index value.
[0016] In a third aspect, the present invention provides a data relationship storage system, which includes a relationship node storage array and a controller, wherein the controller includes: a memory and a processor, the memory and the processor are communicatively connected to each other, computer instructions are stored in the memory, and the processor executes the data relationship storage method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0017] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the data relationship storage method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 is a schematic diagram of the structure of a relationship node storage array according to an embodiment of the present invention;
[0020] Figure 2 is a flow chart of a data relationship storage method according to an embodiment of the present invention;
[0021] Figure 3A is a schematic diagram of a relationship node between a first object and a second object according to an embodiment of the present invention;
[0022] Figure 3B is a node diagram of a role A stored in a relationship node storage array according to an embodiment of the present invention;
[0023] Figure 3C is a node diagram of a role C stored in a relationship node storage array according to an embodiment of the present invention;
[0024] Figure 3D is a schematic diagram of indirect connection of the corresponding relationship nodes of role A according to an embodiment of the present invention;
[0025] Figure 3E is a schematic diagram of indirect connection of role C corresponding relationship nodes according to an embodiment of the present invention;
[0026] Figure 4 is a flow chart of another data relationship storage method according to an embodiment of the present invention;
[0027] Figure 5A is an example diagram of a peer relationship according to an embodiment of the present invention;
[0028] Figure 5B is an example diagram of peer relationship nodes according to an embodiment of the present invention;
[0029] Fig. 6A is an example diagram of a one-to-many relationship according to an embodiment of the present invention;
[0030] Figure 6B is an example diagram of one-to-many relationship nodes according to an embodiment of the present invention;
[0031] Figure 7 is a schematic diagram of the structure of a relationship node storage linked list according to an embodiment of the present invention;
[0032] Figure 8 is a structural block diagram of a data relationship storage device according to an embodiment of the present invention;
[0033] Fig. 9 is a structural block diagram of a data relationship storage system according to an embodiment of the present invention;
[0034] Fig.10 Schematic diagram of the hardware structure of the controller according to the embodiment of the present invention. DETAILED DESCRIPTION
[0035] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0036] In some project requirements, computers need to store and query relationship networks, such as social relationships between people: friends, enemies, classmates, etc. The implementation plan usually includes classification by relationship, recording the other object of each relationship; classification by object, recording all relationships between each object and current data, all of which are aimed at obtaining relationships with a certain data, and many relationships are usually paired or mutual. For example, A has a friend relationship with B, and B must have a friend relationship with A. At this time, A needs to store a copy of B's data, and B also needs to store a copy of A's data, which leads to data redundancy and difficulty in maintenance; and the above scheme usually uses hash structure container storage, which is a container with a fast speed of addition, deletion, query and modification, but occupies a large amount of memory, making the impact of data redundancy more obvious.
[0037] According to an embodiment of the present invention, an embodiment of a data relationship storage method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0038] In this embodiment, a data relationship storage method is provided, which is applied to a data relationship storage system. The data relationship storage system at least includes a relationship node storage array, such as Figure 1The relationship node storage array shown can record the relationship nodes in order. Each array position at the index value records a relationship node. For example, the relationship node corresponding to role A is stored at index 0, and the relationship node corresponding to role B is stored at node 3, i.e., index 2. By storing the relationship nodes in a sequential structure, the memory usage is further reduced (under the same amount of data, the memory usage of the hash container is at least twice that of the sequential container). Figure 2 is a flow chart of a data relationship storage method according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0039] Step S201 , in response to adding a relationship node between a first object and a second object, determining a target index value of the relationship node stored in a relationship node storage array.
[0040] The relationship node at least includes the first object, the second object, the previous relationship node index value of the first object, and the previous relationship node index value of the second object.
[0041] After responding to the operation of adding a relationship node between a first object and a second object in the relationship node storage array, the embodiment of the present invention can firstly Figure 1 The index value stored corresponding to the relationship node is determined in the relationship node storage array shown. In order to effectively realize the content occupancy of the relationship node storage array, the relationship nodes that need to be added can be recorded in sequence in the relationship node storage array. Therefore, it can be determined that the relationship node is stored in an empty position in the relationship node storage array, and then the index value of the position is determined as the target index value of the relationship node stored in the relationship node array.
[0042] The relationship node designed in the embodiment of the present invention at least includes a first object, a second object, a previous relationship node index value of the first object, and a previous relationship node index value of the second object. For example, Figure 3A As shown, the relationship node includes role A, role C, A's previous relationship node index value and C's previous relationship node index value, and may also include the relationship type between role A and role C, just as an example.
[0043] Step S202, obtain the first index value and the second index value of the first object and the second object of the current record that are most recently stored in the relationship node storage array, and update the first index value and the second index value to the previous relationship node index value of the first object and the previous relationship node index value of the second object in the relationship node respectively.
[0044] The embodiment of the present invention can obtain the relationship nodes that have been stored for the first object and the second object respectively, wherein the stored relationship nodes may include the first index value and the second index value of the first object and the second object respectively stored in the relationship node storage array most recently, such as Figure 3B and 3C As shown, the roles A and C with arrows record their latest index values stored in the relationship node storage array, where "empty" can represent the first stored relationship node corresponding to the object, and "peer relationship N" represents the previous relationship node of the object. For example, the first index value can be updated to the previous relationship node index value of the first object in the relationship node, and the second index value can be updated to the previous relationship node index value of the second object in the relationship node, such as Figure 3D and 3E As shown, the previous relationship node index value of A is updated to the first index value of role A most recently stored in the relationship node storage array, and the previous relationship node index value of C is updated to the first index value of role C most recently stored in the relationship node storage array, thereby realizing an indirect connection between the two relationship nodes. When subsequently querying the previous relationship node related to the relationship node, the related previous relationship node can be quickly found directly based on the recorded previous relationship node index value.
[0045] Step S203: Update the first index value and the second index value to target index values respectively.
[0046] The embodiment of the present invention uses the target index value of the relationship node stored in the relationship node storage array as the first index value and the second index value corresponding to the first object and the second object respectively, so as to update the latest array storage index value, such as Figure 3D and 3E As shown, the index value recorded at the role A with an arrow is updated to the target index value, and the index value recorded at the role C with an arrow is updated to the target index value.
[0047] Step S204: storing the updated relationship nodes in a relationship node storage array based on the target index value.
[0048] The embodiment of the present invention can store the updated relationship nodes in the relationship node storage array based on the target index value.
[0049] The data relationship storage method provided in the present embodiment determines, in response to adding a relationship node between a first object and a second object, a target index value of the relationship node stored in a relationship node storage array, obtains the first index value and the second index value of the first object and the second object of the current record that are most recently stored in the relationship node storage array, respectively, and updates the first index value and the second index value to the previous relationship node index value of the first object and the previous relationship node index value of the second object in the relationship node, respectively, and then updates the first index value and the second index value to the target index value, respectively, and finally stores the updated relationship node in the relationship node storage array based on the target index value, thereby realizing a method of storing relationship nodes through data structures and reducing redundant data of the relationship.
[0050] In this embodiment, a data relationship storage method is provided, which is applied to a data relationship storage system. The data relationship storage system at least includes a relationship node storage array. Figure 4 is a flow chart of a data relationship storage method according to an embodiment of the present invention. Figure 4 As shown, the process includes the following steps:
[0051] Step S401, in response to adding a relationship node between a first object and a second object, determining a target index value of the relationship node stored in a relationship node storage array. The relationship node includes at least the first object, the second object, the previous relationship node index value of the first object, and the previous relationship node index value of the second object.
[0052] Specifically, the relationship node storage array includes a peer relationship array and a one-to-many relationship array, and the relationship node also includes a relationship type between the first object and the second object. Determining a target index value of the relationship node stored in the relationship node storage array includes:
[0053] Step S4011: determine whether the relationship type between the first object and the second object is a peer-to-peer relationship type or a one-to-many relationship type.
[0054] Step S4012: If the relationship type between the first object and the second object is a peer-to-peer relationship type, determine a target index value of the relationship node stored in the peer-to-peer relationship array.
[0055] Step S4013: If the relationship type between the first object and the second object is a one-to-many relationship type, determine a target index value of the relationship node stored in the one-to-many relationship array.
[0056] In the embodiment of the present invention, social relationships can be divided into peer relationships and one-to-many relationships. The node of the peer relationship includes the relationship type, the target A of the peer relationship, the target B of the peer relationship, and the next peer relationship between the target A and the target B. For example, Figure 5A As shown, role A and role B are friends, role C and role B are friends, and the corresponding relationship can be established as follows Figure 5B The friend relationship node between role A and role B shown in the figure, a one-to-many relationship includes the relationship type, the one-side of the relationship, the multi-side list of the relationship, and the next one-to-many relationship of all parties in the relationship, for example, Fig. 6A As shown, role A is the teacher of role B and role C, and role B and role C are students of role A. The corresponding Figure 6BThe one-to-many relationship nodes of multiple objects such as role A, role B, and role C shown, including the relationship type of unilateral objects and the relationship type of multi-party objects, are only used as examples. The corresponding relationship node storage arrays can be constructed based on the peer relationship and the one-to-many relationship, and the nodes of different relationships are stored in the relationship node storage arrays of the corresponding types, that is, in response to adding the relationship node of the first object and the second object, the relationship type of the first object and the second object can be determined first. If the relationship type of the first object and the second object is determined to be a peer relationship type, the target index value of the relationship node stored in the peer relationship array can be determined; if the relationship type of the first object and the second object is a one-to-many relationship type, the target index value of the relationship node stored in the one-to-many relationship array can be determined, which is only used as an example.
[0057] The present invention divides social relationships into peer-to-peer relationships and one-to-many relationships, and stores different relationship nodes in respectively corresponding relationship node storage arrays. It not only subdivides the structural types of relationships, uses two types of nodes to save relationships, but also stores them through different storage arrays, which is convenient for subsequent query processing.
[0058] Step S402, obtain the first index value and the second index value of the first object and the second object of the current record, which are respectively stored in the relationship node storage array, and update the first index value and the second index value to the previous relationship node index value of the first object and the previous relationship node index value of the second object in the relationship node. For details, see Figure 2 Step S202 of the illustrated embodiment will not be described in detail here.
[0059] Step S403: Update the first index value and the second index value to the target index value respectively. Figure 2 Step S203 of the illustrated embodiment will not be described in detail here.
[0060] Step S404: store the updated relationship nodes in the relationship node storage array based on the target index value. Figure 2 Step S204 of the illustrated embodiment will not be described in detail here.
[0061] In an optional implementation, in response to querying the target relationship type of the target object, the most recent index value to be queried of the target object currently recorded in the relationship node storage array is obtained; the relationship node corresponding to the target object stored at the index value to be queried is obtained, and it is determined whether the relationship type recorded in the relationship node corresponding to the target object is the target relationship type; if the relationship type recorded in the relationship node corresponding to the target object is the target relationship type, the index value of the relationship node corresponding to the target object stored in the relationship node storage array is recorded; and the index value of the previous relationship node of the target object in the relationship node corresponding to the target object is determined; the index value of the previous relationship node is updated to the index value to be queried, and the step of obtaining the relationship node corresponding to the target object stored at the index value to be queried is returned to execute until it is determined that the index value of the previous relationship node represents the relationship node where the target object is stored for the first time, and all index values of the target relationship type of the target object in the relationship node storage array are obtained.
[0062] In response to querying the target relationship type of the target object, such as querying the friend relationship type of role A, the embodiment of the present invention can independently query from the peer relationship array and the one-to-many relationship array, or pre-determine whether the target relationship type is a peer relationship type or a one-to-many relationship type. After determining the relationship type, it can be queried from the corresponding relationship node storage array, wherein the corresponding relationship node storage array is a peer relationship array and / or a one-to-many relationship array. As an example only, the latest index value to be queried stored in the relationship node storage array of the target object can be obtained, and the relationship node stored at the index value to be queried can be obtained to determine whether the relationship type recorded in the relationship node is the target relationship type to be queried. If so, the relationship node can be recorded in the relationship node storage array. , if not, ignore the relationship node; continue to check the index value of the previous relationship node of the target object in the relationship node, update the index value of the previous relationship node to the index value to be queried, continue to determine whether the relationship type recorded in the relationship node is the target relationship type, and record it until it is determined that the index value of the migration relationship node represents the relationship node for the first storage of the target object, and obtain all index values of the target relationship type of the target object in the relationship node storage array, wherein the method of representing the relationship node for the first storage of the target object is not limited, and the index value of the previous relationship node recorded in the relationship node for the first storage of the target object can be set to "-1" (because the first index value in the array is zero), etc., or it can be set to empty, just as an example.
[0063] In response to the target relationship type of the target object being queried, the present invention can pre-acquire the target object's latest index value to be queried stored in the relationship node storage array, and query forward in sequence based on the previous relationship node index value recorded in the relationship node until the next relationship node is empty, thereby realizing convenient query of relationship nodes through index value query and performing subsequent processing.
[0064] In an optional embodiment, in response to querying the relationship type between the first target object and the second target object, the latest index value to be queried of the first object or the second object of the current record stored in the peer relationship array and the one-to-many relationship array respectively is obtained; the relationship node stored at the index value to be queried corresponding to the first object or the second object is obtained from the peer relationship array and the one-to-many relationship array respectively, and it is determined whether the relationship node is the relationship node of the first target object and the second target object; if the relationship node is the relationship node of the first target object and the second target object, the relationship type of the first object and the second object in the relationship node is recorded; the index value of the previous relationship node of the first target object or the second target object in the relationship node is determined; the index value of the previous relationship node is updated to the index value to be queried, and the step of obtaining the relationship node stored at the index value to be queried corresponding to the first object or the second object is returned until the index value of the previous relationship node of the first target object or the second target object is represented as the relationship node of the first storage of the first target object or the second target object, and all relationship types corresponding to the first target object and the second target object are obtained.
[0065] The embodiment of the present invention responds to querying the relationship type of the first target object and the second target object, such as the relationship type between role A and role B, wherein the relationship type between role A and role B may be a peer-to-peer relationship or a one-to-many relationship, such as role A and role B are colleagues, and role A and role B are also a leader and subordinate. Just as an example, the peer-to-peer relationship array and the one-to-many relationship array may be independently queried, and the query may be performed sequentially based only on the index value of role A, or based on the index value of role B. The present invention takes the query of the index value of role A as an example, and the latest index values to be queried of the currently recorded role A stored in the peer-to-peer relationship array and the one-to-many relationship array may be obtained, and then the peer-to-peer relationship array may be used to query the index values of the currently recorded role A, respectively. The relationship node stored at the corresponding index value to be queried is obtained from the array and the one-to-many relationship array, and then it can be determined whether the target object recorded in the relationship node is the relationship between role A and role B. If so, the relationship type recorded in the relationship node can be recorded as the relationship type between role A and role B. If not, the relationship node can be ignored, and the index value of the previous relationship node of role A recorded in the relationship node can be obtained, and the index value of the previous relationship node of the record can be updated to the index value to be queried, and the previous relationship node of role A is continued to be queried until the index value of the previous relationship node represents the relationship node of role A stored for the first time. Finally, all relationship types of all roles A and role B recorded are returned, just as an example.
[0066] The present invention responds to querying the relationship type between the first target object and the second target object. Since there is only one copy of data, the corresponding relationship nodes can be queried in sequence based on only the first target object or only the second target object, and the number of queries is significantly reduced.
[0067] In an optional implementation, in response to deleting the target relationship type of the target object, it is determined whether the target relationship type is a peer-to-peer relationship type or a one-to-many relationship type; if the target relationship type is a peer-to-peer relationship type, or the target relationship type is a one-to-many relationship type, and the target object is a unilateral object, the index value of the relationship node corresponding to the target object stored in the peer-to-peer relationship array or the one-to-many relationship array, and the index values of the target object and the previous relationship nodes respectively corresponding to another object recorded in the relationship node corresponding to the target object are obtained, and the other object represents at least one object other than the target object in the relationship node corresponding to the target object; the index value of the previous relationship node of the target object recorded in the query is the index value of the previous relationship node stored in the relationship node corresponding to the target object A first node to be updated having an index value stored in a peer-to-peer relationship array or a one-to-many relationship array, and a second node to be updated having an index value of a previous relationship node of another object recorded as an index value of a relationship node corresponding to a target object stored in the peer-to-many relationship array or the one-to-many relationship array; updating the index value of the previous relationship node of the target object recorded in the first node to be updated to the index value of the previous relationship node of the target object recorded in the relationship node corresponding to the target object, and updating the index value of the previous relationship node of another object recorded in the second node to be updated to the index value of the previous relationship node of another object recorded in the relationship node corresponding to the target object; removing the relationship node corresponding to the target object from the peer-to-peer relationship array or the one-to-many relationship array.
[0068] In response to deleting the target relationship type of the target object, an embodiment of the present invention can first determine whether the target relationship type is a peer relationship type or a one-to-many relationship type. For example, if the target relationship type is a friend or colleague, then the relationship type can be determined to be a peer relationship type. If the target relationship type is a teacher-student relationship, then the relationship type can be determined to be a one-to-many relationship type. This is just an example.
[0069] If the embodiment of the present invention determines that the target relationship type is a peer relationship type, such as deleting the friend relationship type of role A, the index value of the friend relationship node of the current role A stored in the peer relationship array can be obtained, such as index 5, and the index value of the previous relationship node of role A recorded in the relationship node can be obtained, such as index 3, and the index value of the previous relationship node of another role other than role A in the relationship node needs to be obtained, such as the index value of the previous relationship node of role B, such as index 2; the first node to be updated with an index value of 5 for the previous relationship node of role A recorded and the second node to be updated with an index value of 5 for the previous relationship node of role B recorded can be obtained; the index value of the previous relationship node of role A recorded in the first node to be updated is updated to index 3, and the index value of the previous relationship node of role B recorded in the second node to be updated is updated to index 2. After the first node to be updated is queried, the relationship node corresponding to the next role A queried is the relationship node stored at index 3, thereby removing the friend relationship node of role A, i.e. the relationship node at index 5, from the peer relationship array.
[0070] If the embodiment of the present invention determines that the target relationship type is a one-to-many relationship type, and the target object is a unilateral object, for example, role A is a teacher, then the relationship node corresponding to role A is removed from the one-to-many relationship node storage array based on the above steps.
[0071] The present invention realizes the removal of the relationship node by changing the index value of the previous relationship node recorded in the relationship node, and the solution is more convenient and simple.
[0072] In an optional implementation, if the target object is a multi-party object, the target object is removed from the relationship node corresponding to the target object; the index value of the relationship node corresponding to the target object stored in the one-to-many relationship array and the index value of the previous relationship node of the target object recorded in the relationship node corresponding to the target object are obtained; the index value of the previous relationship node of the target object recorded is queried as the third node to be updated, whose index value is the index value of the relationship node corresponding to the target object stored in the one-to-many relationship array; and the index value of the previous relationship node of the target object recorded in the third node to be updated is updated to the index value of the previous relationship node of the target object recorded in the relationship node corresponding to the target object.
[0073] If the embodiment of the present invention determines that the target object is a multi-party object, it is only necessary to remove the target object from the relationship node corresponding to the target object. For example, to remove the role D as a classmate from the one-to-many relationship node between teacher and classmate, it is only necessary to obtain the index value of the relationship node corresponding to role D stored in the one-to-many relationship array, such as index 10, and then obtain the index value of the previous relationship node of role D recorded in the relationship node corresponding to role D, such as index 7. Then, the third node to be updated whose index value of the previous relationship node of role D is index 10 can be obtained. The index value of the previous relationship node of role D recorded in the third node to be updated can be updated to index 7 to remove role D. This is just an example.
[0074] In an optional embodiment, the data storage relationship storage system also includes a relationship node storage linked list. In response to converting the relationship node storage array into a relationship node storage linked list, each relationship node in the relationship node storage array is used as a data element in the relationship node storage linked list; based on the index value of each relationship node stored in the relationship node storage array and the index value of the previous relationship node of all objects recorded in each relationship node, they are converted into pointers connecting each data element to obtain a relationship node storage linked list.
[0075] In the data storage system of the embodiment of the present invention, the relationship nodes can be stored not only in the form of an array, but also in the form of a linked list. It is only necessary to use each relationship node in the relationship node storage array as a data element in the relationship node storage linked list, that is, Figure 7 Node 1, node 2, etc. in the relationship node storage linked list shown in the figure can then be converted into pointers linking each data element based on the index value of each relationship node stored in the relationship node storage array and the index value of the previous relationship node of all objects recorded in each relationship node. Figure 7 The relationship node storage linked list shown, in response to adding a relationship node between a first object and a second object, determines a target pointer of the relationship node stored in the relationship node storage linked list, the relationship node includes at least the first object, the second object, the previous relationship node pointer of the first object, and the previous relationship node pointer of the second object, obtains the first pointer and the second pointer of the first object and the second object of the current record, respectively stored in the relationship node storage linked list, and updates the first pointer and the second pointer to the previous relationship node pointer of the first object and the previous relationship node index value of the second object in the relationship node, updates the first pointer and the second pointer to the target pointer, and stores the updated relationship node in the relationship node storage linked list based on the target pointer. This is just an example. For other operations such as deletion, removal and search, please refer to the operation method corresponding to the relationship node storage array described in the above embodiment, which will not be repeated here.
[0076] In the present embodiment, a data relationship storage device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0077] This embodiment provides a data relationship storage device, which is applied to a data relationship storage system. The data relationship storage system at least includes a relationship node storage array, such as Figure 8 As shown, it includes: an index determination module 801, which is used to determine the target index value of the relationship node stored in the relationship node storage array in response to adding the relationship node of the first object and the second object, and the relationship node at least includes the first object, the second object, the previous relationship node index value of the first object and the previous relationship node index value of the second object; a relationship node update module 802, which is used to obtain the first index value and the second index value of the first object and the second object of the current record, which are respectively stored in the relationship node storage array, and update the first index value and the second index value to the previous relationship node index value of the first object and the previous relationship node index value of the second object in the relationship node; an index value update module 803, which is used to update the first index value and the second index value to the target index value respectively; a relationship node storage module 804, which is used to store the updated relationship node in the relationship node storage array based on the target index value.
[0078] In some optional embodiments, the relationship node storage array includes a peer relationship array and a one-to-many relationship array, and the relationship node also includes the relationship type between the first object and the second object. Before determining the target index value of the relationship node stored in the relationship node storage array, the data relationship storage device also includes: a relationship type judgment module, used to judge whether the relationship type between the first object and the second object is a peer relationship type or a one-to-many relationship type; a first index value judgment module, used to determine the target index value of the relationship node stored in the peer relationship array if the relationship type between the first object and the second object is a peer relationship type; a second index value judgment module, used to determine the target index value of the relationship node stored in the one-to-many relationship array if the relationship type between the first object and the second object is a one-to-many relationship type.
[0079] In some optional embodiments, the data relationship storage device also includes: an index value acquisition module, which is used to obtain the latest index value to be queried of the target object currently recorded in the relationship node storage array in response to the target relationship type of the query target object; a relationship type judgment module, which is used to obtain the relationship node corresponding to the target object stored at the index value to be queried, and judge whether the relationship type recorded in the relationship node corresponding to the target object is the target relationship type; an index value recording module, which is used to record the index value stored in the relationship node storage array of the relationship node corresponding to the target object if the relationship type recorded in the relationship node corresponding to the target object is the target relationship type; and determine the index value of the previous relationship node of the target object in the relationship node corresponding to the target object; a sequential query module, which is used to update the index value of the previous relationship node to the index value to be queried, and return to execute the step of obtaining the relationship node corresponding to the target object stored at the index value to be queried, until it is determined that the index value of the previous relationship node is represented as the relationship node where the target object is stored for the first time, and all index values of the target relationship type of the target object in the relationship node storage array are obtained.
[0080] In some optional embodiments, the data relationship storage device further includes: a type query module, which is used to obtain the latest index value to be queried of the first object or the second object of the current record stored in the peer relationship array and the one-to-many relationship array respectively in response to querying the relationship type between the first target object and the second target object; a node judgment module, which is used to obtain the relationship node stored at the index value to be queried corresponding to the first object or the second object from the peer relationship array and the one-to-many relationship array respectively, and judge whether the relationship node is the relationship node of the first target object and the second target object; a relationship type recording module, which is used to record the relationship type of the first object and the second object in the relationship node if the relationship node is the relationship node of the first target object and the second target object; an index determination module, which is used to determine the index value of the previous relationship node of the first target object or the second target object in the relationship node; a repeated execution module, which is used to update the index value of the previous relationship node to the index value to be queried, and return to execute the step of obtaining the relationship node stored at the index value to be queried corresponding to the first object or the second object, until the index value of the previous relationship node of the first target object or the second target object is represented as the relationship node of the first storage of the first target object or the second target object, and all relationship types recorded corresponding to the first target object and the second target object are obtained.
[0081] In some optional implementations, the data relationship storage device further includes: a relationship type deletion module, which is used to determine whether the target relationship type is a peer-to-peer relationship type or a one-to-many relationship type in response to deleting the target relationship type of the target object; an index value search module, which is used to obtain the index value of the relationship node corresponding to the target object stored in the peer-to-peer relationship array or the one-to-many relationship array, and the index value of the target object and the previous relationship node corresponding to the other object recorded in the relationship node corresponding to the target object, if the target relationship type is a peer-to-peer relationship type, or the target relationship type is a one-to-many relationship type, and the target object is a unilateral object, wherein the other object represents at least one object other than the target object in the relationship node corresponding to the target object; a node search module, which is used to query the index value of the previous relationship node of the target object recorded as the target object. A first node to be updated whose index value is the relationship node corresponding to the target object stored in the peer-to-peer relationship array or the one-to-many relationship array, and a second node to be updated whose index value is the previous relationship node of another object stored in the peer-to-many relationship array; an index value updating module, used to update the index value of the previous relationship node of the target object recorded in the first node to be updated to the index value of the previous relationship node of the target object recorded in the relationship node corresponding to the target object, and to update the index value of the previous relationship node of another object recorded in the second node to be updated to the index value of the previous relationship node of another object recorded in the relationship node corresponding to the target object; a node deletion module, used to remove the relationship node corresponding to the target object from the peer-to-peer relationship array or the one-to-many relationship array.
[0082] In some optional embodiments, the data relationship storage device also includes: an object removal module, which is used to remove the target object from the relationship node corresponding to the target object if the target object is a multi-party object; an index search module, which is used to obtain the index value of the relationship node corresponding to the target object stored in the one-to-many relationship array, and the index value of the previous relationship node of the target object recorded in the relationship node corresponding to the target object; a node search module, which is used to query the third to-be-updated node whose index value of the previous relationship node of the target object recorded is the index value of the relationship node corresponding to the target object stored in the one-to-many relationship array; an index value update module, which is used to update the index value of the previous relationship node of the target object recorded in the third to-be-updated node to the index value of the previous relationship node of the target object recorded in the relationship node corresponding to the target object.
[0083] In some optional embodiments, the data relationship storage device also includes: a storage format conversion module, which is used to respond to converting the relationship node storage array into a relationship node storage linked list, and use each relationship node in the relationship node storage array as a data element in the relationship node storage linked list; a pointer conversion module, which is used to convert the index value of each relationship node stored in the relationship node storage array and the index value of the previous relationship node of all objects recorded in each relationship node into a pointer connecting each data element to obtain a relationship node storage linked list.
[0084] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0085] The data relationship storage device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0086] The embodiment of the present invention also provides a data relationship storage system, such as Fig. 9 As shown, the data relationship storage system includes a relationship node storage array and Fig.10 Controller shown.
[0087] See also Fig.10 , Fig.10 is a schematic diagram of the structure of a controller provided by an optional embodiment of the present invention, such as Fig.10 As shown, the controller includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the controller, including instructions stored in or on the memory to display graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple controllers can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Fig.10 A processor 10 is taken as an example.
[0088] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0089] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.
[0090] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required by at least one function; the data storage area may store data created according to the use of the controller, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the controller via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0091] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0092] The controller also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Fig.10 The example of connecting through bus is taken in the following.
[0093] The input device 30 can receive input digital or character information and generate key signal input related to the user settings and function control of the controller, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display and a plasma display. In some optional embodiments, the display device can be a touch screen.
[0094] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0095] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A data relationship storage method, characterized in that: Applied to a data relationship storage system, the data relationship storage system at least includes a relationship node storage array, and the method includes: In response to adding a relationship node between a first object and a second object, determining a target index value of the relationship node stored in the relationship node storage array, wherein the relationship node includes at least the first object, the second object, a previous relationship node index value of the first object, a previous relationship node index value of the second object, and a relationship type between the first object and the second object; Obtain the first index value and the second index value of the first object and the second object of the current record that are respectively most recently stored in the relationship node storage array, and update the first index value and the second index value to the previous relationship node index value of the first object and the previous relationship node index value of the second object in the relationship node respectively; Updating the first index value and the second index value to target index values respectively; The updated relationship nodes are stored in the relationship node storage array based on the target index value.
2. The method according to claim 1, characterized in that: The relationship node storage array includes a peer-to-peer relationship array and a one-to-many relationship array. Before determining the target index value of the relationship node stored in the relationship node storage array, the method further includes: Determining whether the relationship type between the first object and the second object is a peer-to-peer relationship type or a one-to-many relationship type; If the relationship type between the first object and the second object is a peer-to-peer relationship type, determining a target index value of the relationship node stored in the peer-to-peer relationship array; If the relationship type between the first object and the second object is a one-to-many relationship type, a target index value of the relationship node stored in the one-to-many relationship array is determined.
3. The method according to claim 2, characterized in that The method further comprises: In response to the target relationship type of the query target object, obtaining the latest to-be-queried index value of the target object of the current record stored in the relationship node storage array; Obtaining a relationship node corresponding to the target object stored at the index value to be queried, and determining whether the relationship type recorded in the relationship node corresponding to the target object is the target relationship type; If the relationship type recorded in the relationship node corresponding to the target object is the target relationship type, then record the index value of the relationship node corresponding to the target object stored in the relationship node storage array; and determine the index value of the previous relationship node of the target object in the relationship node corresponding to the target object; Update the index value of the previous relationship node to the index value to be queried, return to the step of obtaining the relationship node corresponding to the target object stored at the index value to be queried, until it is determined that the index value of the previous relationship node represents the relationship node where the target object is stored for the first time, and obtain all index values of the target relationship type of the target object in the relationship node storage array.
4. The method according to claim 2, characterized in that: The method further comprises: In response to querying the relationship type between the first target object and the second target object, obtaining the to-be-queried index values of the first object or the second object of the current record that are most recently stored in the peer-to-peer relationship array and the one-to-many relationship array, respectively; Respectively obtaining a relationship node stored at the to-be-queried index value corresponding to the first object or the second object from the peer relationship array and the one-to-many relationship array, and determining whether the relationship node is a relationship node between the first target object and the second target object; If the relationship node is a relationship node between a first target object and a second target object, recording the relationship type between the first object and the second object in the relationship node; Determine an index value of a previous relationship node of the first target object or the second target object in the relationship node; Update the index value of the previous relationship node to the index value to be queried, return to execute the step of obtaining the relationship node stored at the index value to be queried corresponding to the first object or the second object, until the index value of the previous relationship node of the first target object or the second target object is represented as the relationship node for the first storage of the first target object or the second target object, and obtain all relationship types corresponding to the records of the first target object and the second target object.
5. The method according to claim 3, characterized in that: The method further comprises: In response to deleting a target relationship type of a target object, determining whether the target relationship type is a peer-to-peer relationship type or a one-to-many relationship type; If the target relationship type is a peer-to-peer relationship type, or the target relationship type is a one-to-many relationship type, and the target object is a unilateral object, obtaining the index value of the relationship node corresponding to the target object stored in the peer-to-peer relationship array or the one-to-many relationship array, and the index values of the target object and the previous relationship node respectively corresponding to the third object recorded in the relationship node corresponding to the target object, wherein the third object represents at least one other object in the relationship node corresponding to the target object except the target object; Querying a first node to be updated and a second node to be updated, the index value of the previous relationship node of the target object recorded in the first node to be updated is the index value of the relationship node corresponding to the target object stored in the peer-to-peer relationship array or the one-to-many relationship array; the index value of the previous relationship node of the third object recorded in the second node to be updated is the index value of the relationship node corresponding to the target object stored in the peer-to-peer relationship array or the one-to-many relationship array; Update the index value of the previous relationship node of the target object recorded in the first node to be updated to the index value of the previous relationship node corresponding to the target object recorded in the relationship node corresponding to the target object, and update the index value of the previous relationship node of the third object recorded in the second node to be updated to the index value of the previous relationship node corresponding to the third object recorded in the relationship node corresponding to the target object.
6. The method according to claim 5, characterized in that The method further comprises: If the target object is a multi-party object, removing the target object from the relationship node corresponding to the target object; Obtaining the index value of the relationship node corresponding to the target object stored in the one-to-many relationship array, and the index value of the previous relationship node of the target object recorded in the relationship node corresponding to the target object; Query the third node to be updated, where the previous relationship node index value of the target object recorded in the third node to be updated is the index value of the relationship node corresponding to the target object stored in the one-to-many relationship array; The index value of the previous relationship node of the target object recorded in the third node to be updated is updated to the index value of the previous relationship node of the target object recorded in the relationship node corresponding to the target object.
7. The method according to any one of claims 1 to 6, characterized in that The data relationship storage system further includes a relationship node storage linked list, and the method further includes: In response to converting the relationship node storage array into a relationship node storage linked list, taking each relationship node in the relationship node storage array as a data element in the relationship node storage linked list; Based on the index value of each relationship node stored in the relationship node storage array and the index value of the previous relationship node of all objects recorded in each relationship node, they are converted into pointers connecting various data elements to obtain a relationship node storage linked list.
8. A data relationship storage device, characterized in that: Applied to a data relationship storage system, the data relationship storage system at least includes a relationship node storage array, and the device includes: An index determination module, configured to determine, in response to adding a relationship node between a first object and a second object, a target index value of the relationship node stored in the relationship node storage array, wherein the relationship node includes at least the first object, the second object, a previous relationship node index value of the first object, a previous relationship node index value of the second object, and a relationship type between the first object and the second object; A relationship node updating module, used to obtain the first index value and the second index value of the first object and the second object of the current record, which are respectively most recently stored in the relationship node storage array, and update the first index value and the second index value to the previous relationship node index value of the first object and the previous relationship node index value of the second object in the relationship node, respectively; An index value updating module, used to update the first index value and the second index value to target index values respectively; The relationship node storage module is used to store the updated relationship nodes in the relationship node storage array based on the target index value.
9. A data relationship storage system, characterized in that: The data relationship storage system includes a relationship node storage array and a controller, the controller includes: a memory and a processor, the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the data relationship storage method described in any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the data relationship storage method according to any one of claims 1 to 7.
Citation Information
Patent Citations
A complex relationship data storage and retrieval method based on a graph structure
CN109726305A
Linked list implementation method, device and apparatus and readable storage medium
CN109992701A