CN110516122B - Embedded data merging method and device and electronic equipment - Google Patents

Embedded data merging method and device and electronic equipment Download PDF

Info

Publication number
CN110516122B
CN110516122B CN201910828338.9A CN201910828338A CN110516122B CN 110516122 B CN110516122 B CN 110516122B CN 201910828338 A CN201910828338 A CN 201910828338A CN 110516122 B CN110516122 B CN 110516122B
Authority
CN
China
Prior art keywords
dictionary
key
data
nested
array
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910828338.9A
Other languages
Chinese (zh)
Other versions
CN110516122A (en
Inventor
杨之江
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Netease Hangzhou Network Co Ltd
Original Assignee
Netease Hangzhou Network Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Netease Hangzhou Network Co Ltd filed Critical Netease Hangzhou Network Co Ltd
Priority to CN201910828338.9A priority Critical patent/CN110516122B/en
Publication of CN110516122A publication Critical patent/CN110516122A/en
Application granted granted Critical
Publication of CN110516122B publication Critical patent/CN110516122B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • G06F16/90335Query processing

Abstract

The invention provides a method, a device and electronic equipment for merging nested data, and relates to the technical field of data replication, wherein the nested data comprise a plurality of dictionary data, the dictionary data comprise citations and citations corresponding data, the citations corresponding data comprise at least one key value pair, and the key value pair comprises a key and a key value; the method comprises the following steps: acquiring a reference corresponding to each dictionary datum in the nested data; storing each reference into a dictionary array of a pre-constructed dictionary data structure according to the priority sequence of the dictionary data; and applying a dictionary key value query mode or a dictionary traversal mode to the dictionary array with the reference to obtain merged data corresponding to the nested data. The invention can solve the technical problem of high memory and performance overhead caused by data merging through deep copy in the prior art.

Description

Embedded data merging method and device and electronic equipment
Technical Field
The present invention relates to the field of data replication technologies, and in particular, to a method and an apparatus for merging nested data, and an electronic device.
Background
For a data format with multiple layers of nested dictionaries, when multiple copies of such data need to be combined into one copy of data according to different priorities, a deep copy method of decapcopy is generally used. For example, when creating monsters in a game, the data used for initialization is typically divided into four parts: invariant data (for the same monster), rank-related data, editor modification data, program code modification data. Since monster data is hierarchically organized, using shallow copies would corrupt the original data, deepcyp must be used to merge the data, i.e., recursively copy each layer of data. The method of using decapcopy requires an additional memory, which is the same as the merged data. Therefore, there is a relatively large performance overhead in merging these data.
Disclosure of Invention
The invention aims to provide a method and a device for merging nested data and electronic equipment, which are used for solving the technical problem of high memory and performance overhead caused by merging data through deep copy in the prior art.
In the method for merging nested data provided by the embodiment of the present invention, the nested data includes a plurality of dictionary data, the dictionary data includes reference and reference corresponding data, the reference corresponding data includes at least one key-value pair, and the key-value pair includes a key and a key-value; the method comprises the following steps: acquiring a reference corresponding to each dictionary datum in the nested data; storing each reference into a dictionary array of a pre-constructed dictionary data structure according to the priority order of the dictionary data; and applying a dictionary key value query mode or a dictionary traversal mode to the dictionary array with the reference to obtain merged data corresponding to the nested data.
Further, the step of storing each reference in the dictionary array of the pre-constructed dictionary data structure according to the priority order of the dictionary data includes: and storing each reference into a dictionary array of a pre-constructed dictionary data structure one by one according to the sequence of the priority of the dictionary data from low to high.
Further, the step of obtaining merged data corresponding to the nested data by applying a dictionary key value query method to the dictionary array in which the reference is stored includes: and taking keys included in each dictionary datum as current keys one by one, and executing the following steps for each current key: according to the front-back sequence of each reference in the dictionary array, finding out the key value corresponding to the current key from the data corresponding to the reference; and generating merged data corresponding to the nested data according to each key and the corresponding key value thereof.
Further, the step of finding the key value corresponding to the current key from the data corresponding to the reference according to the sequence of each reference in the dictionary array includes: judging whether the current key exists in the data corresponding to the currently traversed reference and judging whether the key value corresponding to the current key is a dictionary; if the current key exists in the data corresponding to the currently traversed reference and the key value corresponding to the current key is not a dictionary, determining the key value as the key value of the current key; and if the current key exists in the data corresponding to the currently traversed reference and the key value corresponding to the current key is a dictionary, adding the dictionary corresponding to the current key into the temporary data cache structure, continuing to traverse the remaining data corresponding to the reference until all the reference traversal is completed, and taking the dictionary in the temporary data cache structure as the key value corresponding to the current key.
Further, the step of generating merged data corresponding to the nested data according to each key and the key value corresponding to the key further includes: aiming at the key value corresponding to each key, the following screening steps are executed: judging whether key values corresponding to the keys comprise a plurality of dictionaries or not, wherein the plurality of dictionaries comprise the same key; if yes, reserving the key with the highest priority and the key value of the dictionary data corresponding to the dictionary to which the key belongs in the plurality of dictionaries; and merging the keys after the screening step and the key values corresponding to the keys to obtain merged data corresponding to the nested data.
Further, the dictionary data structure further includes: deleting the key set; the deleted keys are stored in the deleted key set; before the step of judging whether the current key exists in the data corresponding to the reference of the current traversal, the method further comprises the following steps: judging whether the current key exists in the deletion key set or not; if not, executing the step of judging whether the current key exists in the data corresponding to the reference traversed currently.
Further, the method further comprises: judging whether a self-defined dictionary exists in a dictionary data structure; if yes, setting the dictionary in the temporary data cache structure to a self-defined dictionary at the tail of the dictionary array; and if the dictionary does not exist, creating a new self-defined dictionary at the end of the dictionary array so as to store the dictionary in the temporary data cache structure.
Further, the method further comprises: adding a key to be deleted into a deletion key set; judging whether a self-defined dictionary exists in a dictionary data structure; and if so, deleting the key to be deleted in the custom dictionary.
Further, the step of applying a dictionary traversal method to the dictionary array in which the reference is stored to obtain merged data corresponding to the nested data includes: generating an iterator object in a dictionary data structure, and traversing each reference corresponding data in the dictionary array; for each reference corresponding data, performing the following steps: judging whether the key in the data corresponding to the currently traversed reference exists in the used key set or not; if so, traversing and referencing the next key in the corresponding data; if not, adding the currently traversed key to the used key set, and obtaining a key value corresponding to the currently traversed key by using a dictionary key value query mode; and generating merged data corresponding to the nested data based on each key and the corresponding key value after traversal is completed.
The embodiment of the invention also provides a merging device of nested data, the nested data comprises a plurality of dictionary data, the dictionary data comprises citation and citation corresponding data, the citation corresponding data comprises at least one key value pair, and the key value pair comprises a key and a key value; the device includes: the reference acquisition module is used for acquiring a reference corresponding to each dictionary datum in the nested data; the reference storing module is used for storing each reference into a dictionary array of a pre-constructed dictionary data structure according to the priority sequence of the dictionary data; and the merged data acquisition module is used for applying a dictionary key value query mode or a dictionary traversal mode to the dictionary array stored with the reference to obtain merged data corresponding to the nested data.
The embodiment of the invention also provides electronic equipment which comprises a processor and a memory, wherein the memory stores computer executable instructions capable of being executed by the processor, and the processor executes the computer executable instructions to realize the method for merging the nested data.
Embodiments of the present invention also provide a computer-readable storage medium storing computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the method for merging nested data.
In the merging method of nested data provided in the embodiment of the present invention, the nested data includes a plurality of dictionary data, each dictionary data includes reference and reference corresponding data, the reference corresponding data includes at least one key-value pair, and the key-value pair includes a key and a key value. The method comprises the steps of firstly obtaining a reference corresponding to each dictionary data in nested data, then storing each reference into a dictionary array of a dictionary data structure constructed in advance according to the priority sequence of the dictionary data, and finally applying a dictionary key value query mode or a dictionary traversal mode to the dictionary array in which the references are stored to obtain merged data corresponding to the nested data. The invention can greatly reduce the memory overhead by storing the reference mode of a plurality of dictionary data in the nested data in the dictionary array, and the existing deep copy process is not used in the process of merging the data, so the merging efficiency can be greatly improved and the performance overhead can be reduced in the process of merging the nested data.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
Fig. 1 is a flowchart of a method for merging nested data according to an embodiment of the present invention;
FIG. 2 is a flowchart of another method for merging nested data according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating a key value query process in a method for merging nested data according to an embodiment of the present invention;
fig. 4 is a schematic diagram illustrating a key value setting process in a merging method of nested data according to an embodiment of the present invention;
fig. 5 is a schematic diagram illustrating a key deleting process in the method for merging nested data according to the embodiment of the present invention;
fig. 6 is a schematic diagram illustrating a traversal process in a method for merging nested data according to an embodiment of the present invention;
FIG. 7 is a diagram illustrating a dictionary data structure in a method for merging nested data according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of a merging device for nested data according to an embodiment of the present invention;
fig. 9 is a structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions of the present invention will be described clearly and completely with reference to the following embodiments, and it should be understood that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Considering that the existing merging mode of nested data can only be performed by using a deep copy mode, which is equivalent to creating a new object having the same content and structure as the original data, so that a memory as large as a data memory after merging the nested data needs to be applied, and a large memory overhead and performance overhead are caused. Based on this, embodiments of the present invention provide a method and an apparatus for merging nested data, and an electronic device, which can reduce memory overhead on one hand, reduce performance overhead on the other hand, and improve data merging efficiency when merging nested data.
For the convenience of understanding the present embodiment, a detailed description will be given to a method for merging nested data disclosed in the embodiments of the present application.
Fig. 1 is a flowchart illustrating a merging method of nested data according to an embodiment of the present invention, where the nested data includes a plurality of dictionary data, each dictionary data includes a reference and data corresponding to the reference, and the reference corresponds to the data that includes at least one key-value pair, and each key-value pair includes a key and a key value; the method can be used for merging a plurality of nested dictionary data, and specifically comprises the following steps:
step S102, obtaining the corresponding reference of each dictionary data in the nested data.
Such as: the nested data that is desired to be merged includes the following three dictionary data:
D1={"a":{"b":1,"c":1,"d":{"g":1}}};
D2={"a":{"b":2},"d":{"e":2}};
D3={"d":{"e":3,"f":3}};
in the first dictionary data, D1 represents a reference, and { "a": { "b":1, "c":1, "D": { "g":1} } after the equal sign represents data corresponding to the reference, wherein the data comprises a key-value pair of: the expression of the expression vector is shown in the specification, wherein the expression vector comprises a plurality of expression vectors, and the expression vector comprises a plurality of expression vectors, wherein the expression vectors comprise a plurality of expression vectors, and the expression vectors comprise a plurality of expression vectors.
In this embodiment, first, the references corresponding to each dictionary data in the nested data, that is, D1, D2, and D3, are acquired.
And step S104, storing each reference into a dictionary array of a pre-constructed dictionary data structure according to the priority order of the dictionary data.
The pre-constructed dictionary data structure comprises a dictionary array used for storing the quotations of a plurality of dictionary data, the priority of the dictionary data is determined by a user, the priority sequence of the dictionary data, namely the sequence of the user for storing the data, is stored into the dictionary array firstly, the corresponding dictionary data has low priority, otherwise, the dictionary data has high priority. For example, if the dictionary data structure is contentrect, the merged data D is contentrect (D1, D2, D3); the dictionary array is characterized in that the dictionary array is ditt _ list [ D1, D2, D3], and the priority of dictionary data is D1, D2 and D3 from low to high.
And step S106, applying a dictionary key value query mode or a dictionary traversal mode to the dictionary array stored with the reference to obtain merged data corresponding to the nested data.
After the reference of each dictionary datum is stored in the dictionary array of the contentDict, the final merged datum can be obtained through a dictionary key value query mode or a dictionary traversal mode, or for the above example, a call can be made for each key, such as a call of D [ "a" ], D [ "a" ] [ "b" ], D [ "a" ] [ "c" ], D [ "D" ] [ "e" ] and the like, in each call process, the reference in the dictionary array needs to be traversed so as to find the corresponding key value, and finally, the merged datum of the nested datum is obtained by using the principle that the datum with low priority is covered, such as D { "a" { "b":2, "c":1}, "D" { "e":3, "f":3, "g:1 }.
In the method for merging nested data provided by the embodiment of the invention, the reference corresponding to each dictionary data in the nested data is firstly obtained, then each reference is stored in the dictionary array of the pre-constructed dictionary data structure according to the priority order of the dictionary data, and finally the merged data corresponding to the nested data is obtained by applying the dictionary key value query mode or the dictionary traversal mode to the dictionary array in which the references are stored.
In practical applications, the step of storing each reference in the dictionary array of the pre-constructed dictionary data structure according to the priority order of the dictionary data may further include: and storing each reference into a dictionary array of a pre-constructed dictionary data structure one by one according to the order of the priority of the dictionary data from low to high. For example, if the dictionary data structure is contentrect, the merged data D is contentrect (D1, D2, D3); the dictionary array is characterized in that the dictionary array is dct _ list ═ D1, D2, D3, the priority of the dictionary data is from low to high: d1, D2, D3, so that when data acquisition requires traversing each reference, it starts with the highest priority D3.
The following describes in detail a process of obtaining merged data of nested data by using a dictionary key lookup method, and is shown in fig. 2:
step S202, using the keys included in each dictionary data as current keys one by one, and executing the following steps for each current key: and finding out the key value corresponding to the current key from the data corresponding to the reference according to the front-back sequence of each reference in the dictionary array.
For example, the three dictionary data, D1 { "a": 1, { "b":1, "c":1, "D": { "g":1} } }; d2 { "a": { "b":2}, "D": { "e":2} }; d3 { "D {" e ":3," f ":3} } comprises keys of" a "and" D ", and the keys are respectively used as current keys, and the step of searching the key value corresponding to the current key from the data corresponding to the reference according to the front-back sequence of each reference in the dictionary array is executed.
According to the sequence of each reference in the dictionary array, finding the key value corresponding to the current key from the data corresponding to the reference specifically comprises: judging whether the current key exists in the data corresponding to the currently traversed reference and judging whether the key value corresponding to the current key is a dictionary; if the current key exists in the data corresponding to the currently traversed reference and the key value corresponding to the current key is not a dictionary, determining the key value as the key value of the current key; and if the current key exists in the data corresponding to the currently traversed reference and the key value corresponding to the current key is a dictionary, adding the dictionary corresponding to the current key into the temporary data cache structure, continuing to traverse the remaining data corresponding to the reference until all the reference traversal is completed, and taking the dictionary in the temporary data cache structure as the key value corresponding to the current key.
It should be noted that, the above-mentioned judgment of whether the key value is a dictionary in a dictionary refers to data similar to a key-value pair form except for a simple numerical value, such as: dictionary data D1 is { "a": { "b":1, "c":1, "D": { "g":1} } } in which the key value of "a" is { "b":1, "c":1, "D": { "g":1} }, obviously not a pure numerical value, so that the key values of { "b":1, "c":1, "D": 1, { "g":1} } can be regarded as a dictionary, and the key values of { "b":1, "c":1, "D": 1, { "g":1} are in the dictionary, and are not a dictionary, and the key values of "D" is { "g":1}, obviously a dictionary.
Taking "a" as an example of the current key, the key value query process, that is, the calling process, such as calling D [ "a" ], will search from D3 with the highest priority, find that there is no "a" in D3, and then will search D2; the value V2 { "b":2} corresponding to "a" is found in D2, but since the value is a dictionary, the lookup of D1 needs to be continued; the value V1 { "b":1, "c":1, "D": { "g":1} } corresponding to "a" is found in D1, and is added to the temporary data cache structure each time the value corresponding to "a" is found, which may be a newly created contentditct, i.e., D [ "a" ] ═ contentdit (V1, V2), since D2 is higher than D1, so V2 is higher than V1; storing the references V1 and V2 into a dictionary array of Da, namely, ditt _ list is [ V1 and V2 ]; when querying D [ "a" ] [ "b" ], traversing the reference again, repeating the above process, and finally finding out the key value corresponding to each key.
In practical applications, the dictionary data structure may further include: deleting the key set; such as key _ del, where the delete key set holds deleted keys, such as keys. Therefore, before the step of determining whether the current key exists in the data corresponding to the reference of the current traversal, the following steps can be further included: judging whether the current key exists in the deletion key set or not; if not, executing the step of judging whether the current key exists in the data corresponding to the reference traversed currently.
As shown in fig. 3, a dictionary key query process, i.e., a contentcut. Firstly, judging whether the key is in the key _ del, if so, directly returning to None; and if not, reversely traversing the data corresponding to the reference in the fact _ list, sequentially inquiring the existence of the key, namely judging whether the key is in the data corresponding to the reference in the current traversal, if so, taking out the value from the current dictionary, judging whether the value is the dictionary, and if not, directly returning the value. And when the value is a dictionary, the traversal process needs to be continued, the values corresponding to the keys in all dictionary data are found out and are combined to construct a new contentDict, and meanwhile, the newly created contentDict object is set into the CustomDict (equivalent to a self-defined dictionary) and returned.
The execution speed of the operation is in positive linear correlation with the size of the fact _ list in the ContentDict, and is slower than the value taking speed in a simple dictionary. In practical applications, the number of dit _ list is not too large, and is basically in the order of single digit, so the time complexity of the operation can be considered as O (1).
In addition, after the dictionary in the temporary data cache structure is used as the key value corresponding to the current key, the method further includes: judging whether a self-defined dictionary such as self _ dit in a dictionary data structure exists or not; if yes, setting the dictionary in the temporary data cache structure to a dictionary array, such as a self-defined dictionary at the tail end of the fact _ list; and if the dictionary does not exist, creating a new self-defined dictionary at the end of the dictionary array so as to store the dictionary in the temporary data cache structure.
As shown in fig. 4, a dictionary key setting process, i.e., a contentdict.set process, that can be implemented for the above dictionary data structure is provided. Firstly, judging whether a custom dictionary exists, namely judging whether the value of has _ self _ dit is 1, if the custom dictionary does not exist, creating a new CustomDict (equivalent to the custom dictionary) and placing the CustomDict at the tail of the dit _ list, otherwise, directly setting key-value to the custom dictionary at the tail of the dit _ list.
This operation has the additional overhead of creating a dit object when the custom data is first set, with the time complexity of O (1) otherwise.
Step S204, generating merged data corresponding to the nested data according to each key and the corresponding key value.
In specific implementation, the following screening steps are executed for the key value corresponding to each key: judging whether key values corresponding to the keys comprise a plurality of dictionaries or not, wherein the plurality of dictionaries comprise the same key; if yes, reserving the key with the highest priority and the key value of the dictionary data corresponding to the dictionary to which the key belongs in the plurality of dictionaries; and merging the keys after the screening step and the key values corresponding to the keys to obtain merged data corresponding to the nested data.
For example, the query: "a": the obtained dictionaries are { "b":1, "c":1, "d": { "g":1} and { "b":2} and after final combination, are { "b":2, "c":1, "d": { "g":1} because the priority of the dictionary data in { "b":2} is higher than that in { "b":1, "c":1, "d": { "g":1} } so that the higher priority of "b":2 is kept during combination.
As shown in fig. 5, a process of deleting a key, i.e., a contentpart. The specific process is as follows: adding a key to be deleted into a deletion key set; judging whether a self-defined dictionary exists in a dictionary data structure; and if so, deleting the key to be deleted in the custom dictionary. Adding a key into the set key _ del, judging the value of has _ self _ dit, if the value is 1, then a self-defined dictionary exists, and executing the operation of deleting the key on the self-defined dictionary at the tail end of the dit _ list.
The complexity of the operation time is O (1), but an extra memory space is needed to record the deleted key, and since the dictionary data structure provided by the embodiment is mainly used for merging the data dictionary for object initialization, and less custom addition and deletion are performed, the key _ del cannot be allocated in most cases.
The process of acquiring the merged data of the nested data may be implemented in a dictionary traversal manner, in addition to the dictionary key value query manner, and specifically includes the following processes:
generating an iterator object in a dictionary data structure, and traversing data corresponding to each reference in the dictionary array; for each reference corresponding data, performing the following steps: judging whether the key in the data corresponding to the currently traversed reference exists in the used key set or not; if so, traversing and referencing the next key in the corresponding data; if not, adding the currently traversed key to the used key set, and obtaining a key value corresponding to the currently traversed key by using a dictionary key value query mode; and generating merged data corresponding to the nested data based on each key and the corresponding key value after traversal is completed.
The above examples are also described, for example: for example, D3 { "D": { "e":3, "f":3}, the traversed key is D, and the corresponding key value is { "e":3, "f":3}, and then D2 { "a" { "b":2}, "D": e ":2} }, the keys are a and D, and the corresponding key values are {" b ":2}, and {" e ":2}, respectively, if the user determines that D [" a "] is also a dit structure, i.e., a dictionary, the user will traverse D [" a "] or D [" a "] [" b "] as needed to obtain nested data, and D" a "] in contentdit returns a newly created ContentDict, as in the dictionary key value query process, and the dictionary is not repeated. And when the key value corresponding to each key is determined, the merged data corresponding to the nested data can be obtained.
Referring to fig. 6, a dictionary traversal process, i.e., an iterator. Firstly, generating an iteror object, and traversing each reference corresponding data in the fact _ list; for each reference corresponding data, traversing the key therein; for each key, checking whether the key is in used _ keys, namely the used key set, if so, continuing the traversal, otherwise, adding the key into used _ keys, marking that the key has been traversed, calling ContentDict.get to obtain the value, and returning the value.
The traversal of contentdit is slower than that of the original dit because a new contentdit is created during the traversal, but the added overhead during the traversal is almost negligible compared to the huge overhead of the conventional method using deppyy when merging data.
In the method for merging nested data provided in the embodiment of the present application, a dictionary data structure contentDict is a package of an existing dictionary, and an interface function of the dictionary is implemented, and in a preferred embodiment, the dictionary data structure includes the following parts: dictionary array (dit _ list), presence or absence of custom dictionary (has _ self _ dit), delete key set (key _ del). In addition, the traversal interface (iter) will generate an Iterator object, and temporary variables in the traversal process are all stored in the Iterator object, as shown in fig. 7.
The dictionary data structure ContentDict provided by the embodiment of the invention realizes all interfaces of the dictionary Dict, and can achieve the time complexity of O (1) when a plurality of nested dictionary data are combined, which is far better than deepcopy; although there is additional overhead in the evaluation and traversal compared to the original dictionary, this is within acceptable limits compared to the performance and memory issues associated with deepcopy.
Corresponding to the merging method of the nested data in the foregoing embodiments, this embodiment further provides a merging apparatus of the nested data, where the nested data includes a plurality of dictionary data, the dictionary data includes references and references corresponding data, the references corresponding data includes at least one key-value pair, and the key-value pair includes a key and a key value. Referring to fig. 8, the above apparatus includes: a reference acquisition module 82, a reference deposit module 84, and a merged data acquisition module 86, wherein the functions of each module are as follows:
a reference obtaining module 82, configured to obtain a reference corresponding to each piece of dictionary data in the nested data; a reference storage module 84, configured to store each reference in a dictionary array of a pre-constructed dictionary data structure according to a priority order of the dictionary data; the merged data obtaining module 86 is configured to apply a dictionary key query mode or a dictionary traversal mode to the dictionary array in which the reference is stored, so as to obtain merged data corresponding to the nested data.
In one possible embodiment, the reference storing module 84 is further configured to store the references into the dictionary array of the pre-constructed dictionary data structure one by one according to the order of the priority of the dictionary data from low to high.
In another possible implementation, the merged data obtaining module 86 is further configured to: and taking keys included in each dictionary datum as current keys one by one, and executing the following steps for each current key: according to the front-back sequence of each reference in the dictionary array, finding out the key value corresponding to the current key from the data corresponding to the reference; and generating merged data corresponding to the nested data according to each key and the corresponding key value thereof.
In another possible implementation, the merged data obtaining module 86 is further configured to: judging whether the current key exists in the data corresponding to the currently traversed reference and judging whether the key value corresponding to the current key is a dictionary; if the current key exists in the data corresponding to the currently traversed reference and the key value corresponding to the current key is not a dictionary, determining the key value as the key value of the current key; and if the current key exists in the data corresponding to the currently traversed reference and the key value corresponding to the current key is a dictionary, adding the dictionary corresponding to the current key into the temporary data cache structure, continuing to traverse the remaining data corresponding to the reference until all the reference traversal is completed, and taking the dictionary in the temporary data cache structure as the key value corresponding to the current key.
In another possible implementation, the merged data obtaining module 86 is further configured to: aiming at the key value corresponding to each key, the following screening steps are executed: judging whether key values corresponding to the keys comprise a plurality of dictionaries or not, wherein the plurality of dictionaries comprise the same key; if yes, reserving the key with the highest priority and the key value of the dictionary data corresponding to the dictionary to which the key belongs in the plurality of dictionaries; and merging the keys after the screening step and the key values corresponding to the keys to obtain merged data corresponding to the nested data.
In another possible implementation, the dictionary data structure further includes: deleting the key set; the deleted keys are stored in the deleted key set; the merged data obtaining module 86 is further configured to: judging whether the current key exists in the deletion key set or not; if not, executing the step of judging whether the current key exists in the data corresponding to the reference traversed currently.
In another possible implementation, the merged data obtaining module 86 is further configured to: judging whether a self-defined dictionary exists in a dictionary data structure; if yes, setting the dictionary in the temporary data cache structure to a self-defined dictionary at the tail of the dictionary array; and if the dictionary does not exist, creating a new self-defined dictionary at the end of the dictionary array so as to store the dictionary in the temporary data cache structure.
In another possible implementation, the merged data obtaining module 86 is further configured to: adding a key to be deleted into a deletion key set; judging whether a self-defined dictionary exists in a dictionary data structure; and if so, deleting the key to be deleted in the custom dictionary.
In another possible implementation, the merged data obtaining module 86 is further configured to: generating an iterator object in a dictionary data structure, and traversing each reference corresponding data in the dictionary array; for each reference corresponding data, performing the following steps: judging whether the key in the data corresponding to the currently traversed reference exists in the used key set or not; if so, traversing and referencing the next key in the corresponding data; if not, adding the currently traversed key to the used key set, and obtaining a key value corresponding to the currently traversed key by using a dictionary key value query mode; and generating merged data corresponding to the nested data based on each key and the corresponding key value after traversal is completed.
In the merging device for nested data provided by the embodiment of the invention, the reference corresponding to each dictionary data in the nested data is firstly obtained, then each reference is stored in the dictionary array of the dictionary data structure constructed in advance according to the priority order of the dictionary data, and finally the merged data corresponding to the nested data is obtained by applying the dictionary key value query mode or the dictionary traversal mode to the dictionary array in which the references are stored.
For a brief description, reference may be made to the corresponding contents in the foregoing embodiment of the method for merging nested data, where no mention is made in part of the embodiment of the device for merging nested data.
An embodiment of the present application further provides an electronic device, as shown in fig. 9, which is a schematic structural diagram of the electronic device, where the electronic device includes a processor 91 and a memory 90, the memory 90 stores computer-executable instructions capable of being executed by the processor 91, and the processor 91 executes the computer-executable instructions to implement the merging method of the nested data.
In the embodiment shown in fig. 9, the electronic device further comprises a bus 92 and a communication interface 93, wherein the processor 91, the communication interface 93 and the memory 90 are connected by the bus 92.
The memory 90 may include a high-speed Random Access Memory (RAM) and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory. The communication connection between the network element of the system and at least one other network element is realized through at least one communication interface 93 (which may be wired or wireless), and the internet, a wide area network, a local network, a metropolitan area network, and the like can be used. The bus 92 may be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The bus 92 may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one double-headed arrow is shown in FIG. 9, but this does not indicate only one bus or one type of bus.
The processor 91 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 91. The Processor 91 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present application may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory, and the processor 91 reads the information in the memory and completes the steps of the method for merging nested data of the foregoing embodiment in combination with the hardware thereof.
The embodiment of the present application further provides a computer-readable storage medium, where the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are called and executed by a processor, the computer-executable instructions cause the processor to implement the method for merging nested data, and specific implementation may refer to the foregoing method embodiment, and is not described herein again.
The method for merging nested data, the apparatus for merging nested data, and the computer program product of the electronic device provided in the embodiments of the present application include a computer-readable storage medium storing a program code, where instructions included in the program code may be used to execute the method for merging nested data described in the foregoing method embodiments, and specific implementations may refer to the method embodiments and are not described herein again.
Unless specifically stated otherwise, the relative steps, numerical expressions, and values of the components and steps set forth in these embodiments do not limit the scope of the present application.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings, and are only for convenience of description and simplicity of description, but do not indicate or imply that the device or element being referred to must have a particular orientation, be constructed and operated in a particular orientation, and thus, should not be construed as limiting the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance.
Finally, it should be noted that: the above-mentioned embodiments are only specific embodiments of the present invention, which are used for illustrating the technical solutions of the present invention and not for limiting the same, and the protection scope of the present invention is not limited thereto, although the present invention is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive the technical solutions described in the foregoing embodiments or equivalent substitutes for some technical features within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (12)

1. A method of merging nested data, the nested data comprising a plurality of dictionary data, the dictionary data comprising references and data corresponding to the references, the data corresponding to the references comprising at least one key-value pair, the key-value pair comprising a key and a key-value; characterized in that the method comprises:
acquiring a reference corresponding to each dictionary datum in the nested data;
storing each reference into a dictionary array of a pre-constructed dictionary data structure according to the priority order of the dictionary data;
and applying a dictionary key value query mode or a dictionary traversal mode to the dictionary array stored with the reference to obtain merged data corresponding to the nested data.
2. The method of claim 1, wherein the step of storing each of the references in a dictionary array of a pre-constructed dictionary data structure in a priority order of the dictionary data comprises:
and storing each reference into a dictionary array of a pre-constructed dictionary data structure one by one according to the sequence of the priority of the dictionary data from low to high.
3. The method of claim 1, wherein the step of obtaining merged data corresponding to the nested data by applying a dictionary key query to the dictionary array storing the references comprises:
and taking keys included in each dictionary datum as current keys one by one, and executing the following steps for each current key: according to the front-back sequence of each reference in the dictionary array, finding out the key value corresponding to the current key from the data corresponding to the reference;
and generating merged data corresponding to the nested data according to each key and the key value corresponding to the key.
4. The method of claim 3, wherein the step of finding the key value corresponding to the current key from the data corresponding to each reference according to the sequence of each reference in the dictionary array comprises:
judging whether the current key exists in the data corresponding to the currently traversed reference, and judging whether a key value corresponding to the current key is a dictionary;
if the current key exists in the data corresponding to the currently traversed reference and the key value corresponding to the current key is not a dictionary, determining the key value as the key value of the current key;
and if the current key exists in the data corresponding to the currently traversed reference and the key value corresponding to the current key is a dictionary, adding the dictionary corresponding to the current key into a temporary data cache structure, continuously traversing the data corresponding to the remaining references until all references are traversed, and taking the dictionary in the temporary data cache structure as the key value corresponding to the current key.
5. The method according to claim 4, wherein the step of generating merged data corresponding to the nested data according to each key and its corresponding key value further comprises:
and aiming at the key value corresponding to each key, executing the following screening steps:
judging whether key values corresponding to the keys comprise a plurality of dictionaries, wherein the dictionaries comprise the same keys; if yes, reserving the key with the highest priority and the key value of the dictionary data corresponding to the dictionary to which the key belongs in the plurality of dictionaries;
and merging the keys after the screening step and the key values corresponding to the keys to obtain merged data corresponding to the nested data.
6. The method of claim 4, wherein the dictionary data structure further comprises: deleting the key set; wherein, the deleted key set stores deleted keys;
before the step of judging whether the current key exists in the data corresponding to the currently traversed reference, the method further includes:
judging whether the current key exists in the deletion key set or not;
and if not, executing the step of judging whether the current key exists in the data corresponding to the reference of the current traversal.
7. The method of claim 4, further comprising:
judging whether a self-defined dictionary in the dictionary data structure exists or not;
if yes, setting the dictionary in the temporary data cache structure to the custom dictionary at the tail of the dictionary array;
and if the dictionary does not exist, creating a new self-defined dictionary at the tail of the dictionary array so as to store the dictionary in the temporary data cache structure.
8. The method of claim 6, further comprising:
adding a key to be deleted into the deletion key set;
judging whether a self-defined dictionary in the dictionary data structure exists or not;
and if so, deleting the key to be deleted in the custom dictionary.
9. The method of claim 1, wherein the step of applying a dictionary traversal to the dictionary array storing the references to obtain merged data corresponding to the nested data comprises:
generating an iterator object in the dictionary data structure, and traversing data corresponding to each reference in the dictionary array; for each reference corresponding data, performing the following steps:
judging whether the key in the data corresponding to the currently traversed reference exists in the used key set or not; if so, traversing the next key in the data corresponding to the reference; if not, adding the currently traversed key to the used key set, and obtaining a key value corresponding to the currently traversed key by using a dictionary key value query mode;
and generating merged data corresponding to the nested data based on each key and the corresponding key value after traversal is completed.
10. A merging device of nested data, the nested data containing a plurality of dictionary data, the dictionary data including references and data corresponding to the references, the data corresponding to the references including at least one key-value pair, the key-value pair including a key and a key value; characterized in that the device comprises:
the reference acquisition module is used for acquiring a reference corresponding to each dictionary datum in the nested data;
the reference storage module is used for storing each reference into a dictionary array of a pre-constructed dictionary data structure according to the priority sequence of the dictionary data;
and the merged data acquisition module is used for applying a dictionary key value query mode or a dictionary traversal mode to the dictionary array stored with the reference to obtain merged data corresponding to the nested data.
11. An electronic device comprising a processor and a memory, the memory storing computer-executable instructions executable by the processor, the processor executing the computer-executable instructions to implement the method of any of claims 1 to 9.
12. A computer-readable storage medium having computer-executable instructions stored thereon which, when invoked and executed by a processor, cause the processor to implement the method of any of claims 1 to 9.
CN201910828338.9A 2019-09-03 2019-09-03 Embedded data merging method and device and electronic equipment Active CN110516122B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910828338.9A CN110516122B (en) 2019-09-03 2019-09-03 Embedded data merging method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910828338.9A CN110516122B (en) 2019-09-03 2019-09-03 Embedded data merging method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN110516122A CN110516122A (en) 2019-11-29
CN110516122B true CN110516122B (en) 2022-05-13

Family

ID=68630529

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910828338.9A Active CN110516122B (en) 2019-09-03 2019-09-03 Embedded data merging method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN110516122B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112100987A (en) * 2020-09-27 2020-12-18 中国建设银行股份有限公司 Transcoding method and device for multi-source data dictionary

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1989486A (en) * 2004-05-20 2007-06-27 Sap股份公司 Sharing objects in runtime systems
CN106933823A (en) * 2015-12-29 2017-07-07 北京国双科技有限公司 Method of data synchronization and device
CN108038018A (en) * 2017-12-22 2018-05-15 杭州闪捷信息科技有限公司 Expansible daily record data storage method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7219340B2 (en) * 2003-10-23 2007-05-15 Microsoft Corporation Changeable class and pattern to provide selective mutability in computer programming environments

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1989486A (en) * 2004-05-20 2007-06-27 Sap股份公司 Sharing objects in runtime systems
CN106933823A (en) * 2015-12-29 2017-07-07 北京国双科技有限公司 Method of data synchronization and device
CN108038018A (en) * 2017-12-22 2018-05-15 杭州闪捷信息科技有限公司 Expansible daily record data storage method and device

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
"Python中变量在内存的存储与地址变化详解(深浅拷贝,值/引用传递、可变不可变数据类型)";Z小旋;《https://blog.csdn.net/as480133937/article/details/87305247》;20190221;全文 *
"无限遍历,Python实现在多维嵌套字典、列表、元组的JSON中获取数据";_BingoHe;《https://www.cnblogs.com/Detector/p/8085460.html》;20171222;第1-4页 *
"通过数据值引用保存数据并减少数据副本";佚名;《https://zone.ni.com/reference/zhs-XX/help/371361R-0118/lvconcepts/external_data_val_ref/》;20180331;全文 *

Also Published As

Publication number Publication date
CN110516122A (en) 2019-11-29

Similar Documents

Publication Publication Date Title
CN108255958B (en) Data query method, device and storage medium
US10680645B2 (en) System and method for data storage, transfer, synchronization, and security using codeword probability estimation
CN111249736B (en) Code processing method and device
US20160275078A1 (en) Parallel build of non-partitioned join hash tables and non-enforced n:1 join hash tables
US9645828B2 (en) Method of searching character string, character string searching device, and recording medium
WO2020034810A1 (en) Search method and apparatus, computer device and storage medium
CN106599111B (en) Data management method and storage system
CN112099725A (en) Data processing method and device and computer readable storage medium
CN108140050A (en) A kind of method and device using Bloom filter filtering file
CN111159329A (en) Sensitive word detection method and device, terminal equipment and computer-readable storage medium
CN109460406B (en) Data processing method and device
US20170277811A1 (en) Efficient conditional state mapping in a pattern matching automaton
JP6726690B2 (en) Performing multidimensional search, content-associative retrieval, and keyword-based retrieval and retrieval on losslessly reduced data using basic data sieves
CN107784073B (en) Data query method for local cache, storage medium and server
CN110516122B (en) Embedded data merging method and device and electronic equipment
CN111638925A (en) Interface method table generation method, function pointer query method and device
CN110311826B (en) Network equipment configuration method and device
CN112511629A (en) Data compression method and system for account tree of MPT structure
CN115292737A (en) Multi-keyword fuzzy search encryption method and system and electronic equipment
CN111061927A (en) Data processing method and device and electronic equipment
CN113742050B (en) Method, device, computing equipment and storage medium for operating data object
CN110231935B (en) Script execution and updating method, device, equipment and storage medium
CN113779029A (en) Data query method and device
JP2000339332A (en) Medium recording retrieval index, method and device for updating retrieval index and medium recording its program
US10795875B2 (en) Data storing method using multi-version based data structure

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant