CN110516122A - 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
CN110516122A
CN110516122A CN201910828338.9A CN201910828338A CN110516122A CN 110516122 A CN110516122 A CN 110516122A CN 201910828338 A CN201910828338 A CN 201910828338A CN 110516122 A CN110516122 A CN 110516122A
Authority
CN
China
Prior art keywords
data
dictionary
key
nested
merging
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.)
Granted
Application number
CN201910828338.9A
Other languages
Chinese (zh)
Other versions
CN110516122B (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

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

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Machine Translation (AREA)

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

Merging method, device and the electronic equipment of nested data
Technical field
The present invention relates to Data Replication Technology in Mobile field, more particularly, to a kind of merging method of nested data, device and Electronic equipment.
Background technique
For there is the data format of multilayer nest dictionary, when needs merge more parts of such data according to the different of priority When at a data, it is common practice to use deepcopy depth copy mode.For example, when creating the monster in game, The data that would commonly be used for initialization are divided into four parts: persistent data (for same monster), is compiled grade related data Collect device modification data, program code modifies data.Since monster data are laminated tissues, will be destroyed using shallow copy original Data you must use deepcopy and carry out merging data, i.e. recurrence copies each layer data.And use deepcopy Mode need to apply one piece of extra memory, memory size is identical with the data after merging.Therefore, merging these data procedures In have bigger performance cost.
Summary of the invention
The purpose of the present invention is to provide merging method, device and the electronic equipments of a kind of nested data, to alleviate The technical problem big by memory caused by deep copy progress data merging and performance cost in the prior art.
A kind of merging method of nested data provided in an embodiment of the present invention, nested data include multiple dictionary numbers According to dictionary data includes reference and quotes corresponding data, and quoting corresponding data includes at least one key-value pair, key-value pair packet Include key and key assignments;This method comprises: obtaining the corresponding reference of each dictionary data in nested data;According to dictionary data Each reference is stored in the dictionary array of the dictionary data structure constructed in advance by priority orders;To the dictionary for having reference Array application dictionary key assignments inquiry mode or dictionary traverse mode, obtain the corresponding merging data of nested data.
Further, the above-mentioned priority orders according to dictionary data, the dictionary number that each reference deposit is constructed in advance According to the priority sequence from low to high that the step in the dictionary array of structure includes: according to dictionary data, by each reference by In the dictionary array for the dictionary data structure that one deposit constructs in advance.
Further, above-mentioned to the dictionary array application dictionary key assignments inquiry mode for having reference, obtain nested data The step of corresponding merging data, comprising: it regard the key that each dictionary data includes as current key one by one, it is equal to each current key It executes following steps: according to tandem of each reference in dictionary array, being found currently from quoting in corresponding data The corresponding key assignments of key;According to each key and its corresponding key assignments, the corresponding merging data of nested data is generated.
Further, the above-mentioned tandem according to each reference in dictionary array, is looked into from quoting in corresponding data The step of finding current key corresponding key assignments, comprising: judge that current key whether there is in the corresponding data of reference currently traversed In, and judge whether the corresponding key assignments of current key is dictionary;If current key is present in the corresponding number of the reference currently traversed In, and the current corresponding key assignments of key is not dictionary, and key assignments is determined as to the key assignments of current key;If current key is present in currently In the corresponding data of the reference of traversal, and the current corresponding key assignments of key is dictionary, and the corresponding dictionary of current key is added to temporarily In data buffer storage structure, continue to traverse the corresponding data of remaining reference, until all references traversal completion, ephemeral data is cached Dictionary in structure, as the corresponding key assignments of current key.
Further, above-mentioned according to each key and its corresponding key assignments, generate the corresponding merging data of nested data Step, further includes: be directed to the corresponding key assignments of each key, execute following screening step: judge in the corresponding key assignments of key whether include Multiple dictionaries, and include identical key in multiple dictionaries;If so, retaining the corresponding word of dictionary belonging to key in multiple dictionaries The key and its key assignments of the highest priority of allusion quotation data;By after screening step key and its corresponding key assignments merge, obtain embedding The corresponding merging data of set type data.
Further, above-mentioned dictionary data structure further include: delete key set;Wherein, delete key set, which is preserved, has deleted The key removed;Before judging that current key whether there is the step in the corresponding data of reference currently traversed, further includes: judgement is worked as Preceding key whether there is in delete key set;Judge that current key whether there is in the reference currently traversed if it does not, executing Step in corresponding data.
Further, the above method further include: judge that the custom dictionaries in dictionary data structure whether there is;If deposited Dictionary in ephemeral data buffer structure is being arranged into the custom dictionaries at dictionary array end;If it does not, in word The end of allusion quotation array creates new custom dictionaries, to store the dictionary in ephemeral data buffer structure.
Further, the above method further include: delete key set is added in key to be deleted;Judge in dictionary data structure Custom dictionaries whether there is;If it does, deleting the key to be deleted in custom dictionaries.
Further, above-mentioned that mode is traversed to the dictionary array application dictionary for having reference, it is corresponding to obtain nested data Merging data the step of, comprising: generate an iterator objects in dictionary data structure, each draw in traversal dictionary array With corresponding data;For the corresponding data of each reference, it is performed both by following steps: the corresponding number of reference that judgement currently traverses Key in whether there is in being closed with keyset;If so, traversal quotes next key in corresponding data;If not, The key currently traversed is added in being closed with keyset, and uses dictionary key assignments inquiry mode, the key currently traversed is corresponding Key assignments;Based on key each after the completion of traversal and its corresponding key assignments, the corresponding merging data of nested data is generated.
The embodiment of the present invention also provides a kind of merging device of nested data, and nested data include multiple dictionary numbers According to dictionary data includes reference and quotes corresponding data, and quoting corresponding data includes at least one key-value pair, key-value pair packet Include key and key assignments;The device includes: that reference obtains module, and for obtaining, each dictionary data in nested data is corresponding to be drawn With;Reference deposit module, for the priority orders according to dictionary data, the dictionary data that each reference deposit is constructed in advance In the dictionary array of structure;Merging data obtains module, for the dictionary array application dictionary key assignments issuer for having reference Formula or dictionary traverse mode, obtain the corresponding merging data of nested data.
The embodiment of the present invention also provides a kind of electronic equipment, including processor and memory, and memory is stored with can be by The computer executable instructions that processor executes, processor execute computer executable instructions to realize above-mentioned nested data Merging method.
The embodiment of the present invention also provides a kind of computer readable storage medium, which has meter Calculation machine executable instruction, when being called and being executed by processor, computer executable instructions promote the computer executable instructions Processor realizes the merging method of above-mentioned nested data.
In the merging method of nested data provided in an embodiment of the present invention, nested data include multiple dictionary datas, Each dictionary data includes reference and quotes corresponding data, and quoting corresponding data includes at least one key-value pair, key-value pair Including key and key assignments.The corresponding reference of each dictionary data in nested data is obtained first, then according to dictionary data Priority orders, in the dictionary array of dictionary data structure that each reference deposit is constructed in advance, finally to there being reference Dictionary array application dictionary key assignments inquiry mode or dictionary traverse mode, obtain the corresponding merging data of nested data.This Invention can be substantially reduced interior by way of storing the reference of multiple dictionary datas in nested data in dictionary array Expense is deposited, and does not use existing deep copy procedure during merging data, therefore, in the mistake that nested data merge Combined efficiency can be greatly promoted in journey, reduce performance cost.
Detailed description of the invention
It, below will be to specific in order to illustrate more clearly of the specific embodiment of the invention or technical solution in the prior art Embodiment or attached drawing needed to be used in the description of the prior art be briefly described, it should be apparent that, it is described below Attached drawing is some embodiments of the present invention, for those of ordinary skill in the art, before not making the creative labor It puts, is also possible to obtain other drawings based on these drawings.
Fig. 1 is a kind of flow chart of the merging method of nested data provided in an embodiment of the present invention;
Fig. 2 is the merging method flow chart of another nested data provided in an embodiment of the present invention;
Fig. 3 is the signal of key assignments query process in a kind of merging method of nested data provided in an embodiment of the present invention Figure;
Fig. 4 is the signal of key assignments setting up procedure in a kind of merging method of nested data provided in an embodiment of the present invention Figure;
Fig. 5 is the schematic diagram of delete key process in a kind of merging method of nested data provided in an embodiment of the present invention;
Fig. 6 is the schematic diagram of ergodic process in a kind of merging method of nested data provided in an embodiment of the present invention;
Fig. 7 is the signal of dictionary data structure in a kind of merging method of nested data provided in an embodiment of the present invention Figure;
Fig. 8 is a kind of structural schematic diagram of the merging device of nested data provided in an embodiment of the present invention;
Fig. 9 is the structure chart of a kind of electronic equipment provided in an embodiment of the present invention.
Specific embodiment
Technical solution of the present invention is clearly and completely described below in conjunction with embodiment, it is clear that described reality Applying example is a part of the embodiment of the present invention, instead of all the embodiments.Based on the embodiments of the present invention, the common skill in this field Art personnel every other embodiment obtained without making creative work belongs to the model that the present invention protects It encloses.
In view of the merging mode of existing nested data, the mode copied deeply can only be used to carry out, be equivalent to creation The new object of one and former data content and structure striking resemblances, so that the data after needing application to merge with nested data The equally big memory of memory causes very big memory overhead and performance cost.Based on this, the embodiment of the present invention provides a kind of nesting On the one hand merging method, device and the electronic equipment of type data can reduce memory overhead, separately when merging to nested data On the one hand performance cost can be reduced, data merging efficiency is improved.
For the conjunction convenient for understanding the present embodiment, first to a kind of nested data disclosed in the embodiment of the present application And method describes in detail.
Fig. 1 shows a kind of flow chart of the merging method of nested data provided in an embodiment of the present invention, the nested It include multiple dictionary datas in data, each dictionary data includes quoting data corresponding with the reference, quotes corresponding data In again include at least one key-value pair, each key-value pair includes key and key assignments;This method can dictionary number to multiple nesteds According to merging, specifically includes the following steps:
Step S102 obtains the corresponding reference of each dictionary data in nested data.
Such as: wanting combined nested data includes following three dictionary datas:
D1=" a ": " b ": 1, " c ": 1, " d ": { " g ": 1 } } };
D2=" a ": " b ": 2 }, " d ": { " e ": 2 } };
D3=" d ": " e ": 3, " f ": 3 } };
In first character allusion quotation data, D1 indicate reference, equal sign it is subsequent " a ": " b ": 1, " c ": 1, " d ": { " g ": 1 } } } Indicate the corresponding data of the reference, in the data, including a key-value pair are as follows: " a ": " b ": 1, " c ": 1, " d ": " g ": 1 } }, Wherein, " a " indicates key, and " b ": 1, " c ": 1, " d ": { " g ": 1 } } indicate " a " corresponding key assignments.
In the present embodiment, the corresponding reference of each dictionary data in nested data, that is, D1, D2 are got first And D3.
Step S104, according to the priority orders of dictionary data, the dictionary data knot that each reference deposit is constructed in advance In the dictionary array of structure.
It include dictionary array in the dictionary data structure constructed in advance, for storing the reference of multiple dictionary datas, dictionary The priority of data, is determined by user, the priority orders of dictionary data, that is, user is stored in the sequence of data, is first stored in The priority of reference in dictionary array, corresponding dictionary data is low, conversely, the priority of dictionary data is high.For example, dictionary Data structure is ContentDict, then, and merging data D=ContentDict (D1, D2, D3);Dictionary array therein is Dict_list=[D1, D2, D3], the priority of dictionary data are D1, D2, D3 from low to high.
Step S106 traverses mode to the dictionary array application dictionary key assignments inquiry mode or dictionary for having reference, obtains To the corresponding merging data of nested data.
After by the dictionary array of the reference deposit ContentDict of above-mentioned each dictionary data, pass through dictionary key assignments Inquiry mode or dictionary traverse the available final merging data of mode, or with for above-mentioned example, can be directed to every A key is called, such as calls D [" a "], D [" a "] [" b "], D [" a "] [" c "], D [" d "], D [" d "] [" e "], above-mentioned In each calling process, the reference in dictionary array is needed to be traversed for, to find corresponding key value, is finally covered with high priority The data of low priority be principle, obtain the merging data of nested data, as D=" a ": " b ": 2, " c ": 1 }, " d ": " e":3,"f":3,"g":1}}。
Each word in the merging method of nested data provided in an embodiment of the present invention, first in acquisition nested data The corresponding reference of allusion quotation data, then according to the priority orders of dictionary data, the dictionary number that each reference deposit is constructed in advance According in the dictionary array of structure, finally to the dictionary array application dictionary key assignments inquiry mode or dictionary traversal side for having reference Formula, obtains the corresponding merging data of nested data, and this method is multiple in nested data by storing in dictionary array The mode of the reference of dictionary data substantially reduces memory overhead, and does not use existing depth during merging data and copy Therefore shellfish process can greatly promote combined efficiency during nested data merge, reduce performance cost.
In practical applications, the above-mentioned priority orders according to dictionary data, the word that each reference deposit is constructed in advance Step in the dictionary array of allusion quotation data structure can also include: the priority sequence from low to high according to dictionary data, will Each reference is stored in one by one in the dictionary array of the dictionary data structure constructed in advance.For example, dictionary data structure is ContentDict, then, and merging data D=ContentDict (D1, D2, D3);Dictionary array therein is dict_list= [D1, D2, D3], the priority of dictionary data is from low to high are as follows: D1, D2, D3, in this way, needing to be traversed for each draw obtaining data It used time, can be since the D3 of highest priority.
The process for obtaining the merging data of nested data by dictionary key assignments inquiry mode is described in detail below, joins As shown in Figure 2:
Step S202 regard the key that each dictionary data includes as current key one by one, is performed both by each current key following Step: quoting the tandem in dictionary array according to each, and it is corresponding to find current key from the corresponding data of reference Key assignments.
For example, above three dictionary data, D1=" a ": " b ": 1, " c ": 1, " d ": { " g ": 1 } } };D2=" a ": " b":2},"d":{"e":2}};D3=" d ": " e ": 3, " f ": in 3 } }, including key be " a " and " d ", respectively with " a " and " D " is used as current key, executes the tandem according to each reference in dictionary array, finds from quoting in corresponding data The step of current key corresponding key assignments.
According to tandem of each reference in dictionary array, current key is found from the corresponding data of reference and is corresponded to Key assignments specifically include: judge that current key whether there is in the corresponding data of reference currently traversed, and judge current key Whether corresponding key assignments is dictionary;If current key is present in the corresponding data of the reference currently traversed, and current key is corresponding Key assignments be not dictionary, key assignments is determined as to the key assignments of current key;If it is corresponding that current key is present in the reference currently traversed In data, and the current corresponding key assignments of key is dictionary, and the corresponding dictionary of current key is added in ephemeral data buffer structure, after Continuous traversal is remaining to quote corresponding data, until all references traversal is completed, by the dictionary in ephemeral data buffer structure, as The corresponding key assignments of current key.
It should be noted that above-mentioned judgement key assignments is that dictionary in dictionary refers to class except non-simple numerical value The data of key-value pair form are similar to, such as: dictionary data D1=" a ": " b ": 1, " c ": 1, " d ": " g ": in 1 } } }, " a's " Key assignments be " b ": 1, " c ": 1, " d ": " g ": 1 } }, it is clear that be not simple numerical value, therefore, and " b ": 1, " c ": 1, " d ": " G ": can 1 } } regard a dictionary as, and " b ": 1, " c ": 1, " d ": { " g ": in 1 } }, the key assignments of " b " is 1, is not one A dictionary, the key assignments of " d " are { " g ": 1 }, it is clear that be a dictionary.
By taking " a " is current key as an example, key assignments query process i.e. calling process such as call D [" a "], understand from preferential The highest D3 of grade has been looked into, and is found do not have " a " in D3, then can be gone to look into D2;Had found in D2 " a " corresponding value V2=" b ": 2 }, But since the value is a dictionary, it is therefore desirable to continue to look into D1;Had found in D1 " a " corresponding value V1=" b ": 1, " c ": 1, " D ": { " g ": 1 } }, when finding " a " corresponding value every time, adding it in ephemeral data buffer structure, which can be with It is a newly created ContentDict, i.e. D [" a "]=ContentDict (V1, V2), because D2 priority is greater than D1, institute It is greater than V1 with V2 priority;V1 will be quoted again, and V2 is stored in the dictionary array of Da, i.e. dict_list=[V1, V2];Inquiry D [" A "] [" b "] when, then reference is traversed, it repeats the above process, the corresponding key assignments of each key may finally be found.
In practical applications, above-mentioned dictionary data structure can also include: delete key set;Such as key_del, wherein delete Except deleted key, such as key are preserved in keyset conjunction.Therefore, judging that it is corresponding in the reference currently traversed that current key whether there is Data in step before, can with the following steps are included: judge current key whether there is in delete key set;If no In the presence of execution judges that current key whether there is the step in the corresponding data of reference currently traversed.
As shown in figure 3, for a kind of dictionary key assignments query process that above-mentioned dictionary data structure may be implemented, i.e., ContentDict.get process.Key is first determined whether in key_del, if it is present directly returning to None;Otherwise anti- Corresponding data are quoted into traversal dict_list, successively inquire the existence of key, that is, judge whether key is currently traversing It quotes in corresponding data, if key exists, takes out value from current dictionary, judge that value is dictionary, if Value is not that dictionary then directly returns to value.And in the case that value is dictionary, then it needs to continue ergodic process, find out The corresponding value of key in all dictionary datas, and they are merged and is configured to new ContentDict, while will be newly created ContentDict object is arranged in CustomDict (being equivalent to custom dictionaries) and returns.
The linear positive correlation of size of dict_list in the execution speed and ContentDict of the operation, than simple word The speed of value is slow in allusion quotation.In practical applications, the quantity of dict_list tends not to too much, substantially in the quantity of units Grade, therefore the time complexity of this operation may be considered O (1).
In addition, in the above-mentioned dictionary by ephemeral data buffer structure, after the corresponding key assignments of current key, above-mentioned side Method further include: judge the custom dictionaries in dictionary data structure, such as self_dict, if exist;If it does, by interim Dictionary setting in data buffer storage structure to dictionary array, as the end dict_list custom dictionaries in;If it does not, New custom dictionaries is created, at the end of dictionary array to store the dictionary in ephemeral data buffer structure.
As shown in figure 4, for a kind of dictionary key assignments setting up procedure that above-mentioned dictionary data structure may be implemented, i.e., ContentDict.set process.First determine whether that custom dictionaries whether there is, that is, judge has_self_dict value whether be 1, if custom dictionaries there is not yet, creates new CustomDict (being equivalent to custom dictionaries) and be put into dict_list End, otherwise directly by key-value be arranged into the custom dictionaries at the end dict_list.
The operation has the overhead of additional creation dict object, other situations when self-defining data is arranged for the first time Under time complexity be O (1).
Step S204 generates the corresponding merging data of nested data according to each key and its corresponding key assignments.
When it is implemented, be directed to the corresponding key assignments of each key, execute following screening step: judge be in the corresponding key assignments of key No includes multiple dictionaries, and includes identical key in multiple dictionaries;If so, retaining dictionary pair belonging to key in multiple dictionaries The key and its key assignments of the highest priority for the dictionary data answered;By after screening step key and its corresponding key assignments merge, Obtain the corresponding merging data of nested data.
For example, inquiry: " a ": obtained dictionary be " b ": 1, " c ": 1, " d ": " g ": 1 } } and " b ": 2 }, final merging Afterwards, for " b ": 2, " c ": 1, " d ": " g ": 1 } } since " b ": the priority of the dictionary data where 2 } be higher than " b ": 1, " C ": 1, " d ": " g ": the priority of the dictionary data where 1 } }, so when merging it is higher " b " that priority can be retained: 2.
As shown in figure 5, a kind of process for the delete key that may be implemented for above-mentioned dictionary data structure, i.e., ContentDict.del process.Detailed process are as follows: delete key set is added in key to be deleted;Judge in dictionary data structure Custom dictionaries whether there is;If it does, deleting the key to be deleted in custom dictionaries.Key is added and is gathered In key_del, the value of has_self_dict is then judged, if value is 1, there are custom dictionaries, to the end dict_list The custom dictionaries of tail executes the operation for deleting key.
The operating time complexity is O (1), but one piece of additional memory headroom is needed to record the key deleted, by Merge in the data dictionary that dictionary data structure provided in this embodiment is mainly used for object initialization, it is less to carry out customized increasing It deletes, therefore, key_del will not be allocated out in most cases.
The process of the merging data of above-mentioned acquisition nested data, in addition to can use above-mentioned dictionary key assignments inquiry mode It realizes, mode can also be traversed to realize using dictionary, specifically include following procedure:
An iterator objects are generated in dictionary data structure, the corresponding data of each reference in traversal dictionary array; For the corresponding data of each reference, be performed both by following steps: whether the key in the corresponding data of reference that judgement currently traverses It is present in being closed with keyset;If so, traversal quotes next key in corresponding data;If not, will currently traverse Key is added to be closed with keyset, and uses dictionary key assignments inquiry mode, the corresponding key assignments of the key currently traversed;Based on time Each key and its corresponding key assignments after the completion of going through generate the corresponding merging data of nested data.
Also it is illustrated with above-mentioned example, such as: such as D3=" d ": " e ": 3, " f ": 3 } }, the key of traversal is d, right The key assignments answered be " e ": 3, " f ": 3 }, just finishing, and then traversing D2=again, { " a ": { " b ": 2 }, " d ": { " e ": 2 } }, key is A and d, corresponding key assignments be respectively " b ": 2 }, and " e ": 2 }, if user determine D [" a "] be also a dict structure, That is dictionary, user can traverse D [" a "] or D [" a "] [" b "] as needed to obtain nested data, ContentDict That middle D [" a "] returns is a newly created ContentDict, as dictionary key assignments query process above-mentioned, herein no longer It repeats.After determining each key corresponding key assignments, the corresponding merging data of nested data can be obtained.
It is shown in Figure 6, it is a kind of dictionary ergodic process that above-mentioned dictionary data structure may be implemented, i.e., Iterator.next process.It firstly generates an Iterator object, traverses the corresponding data of each reference in dict_list; Data corresponding for each reference, traverse key therein;For each key, whether key is in used_keys for inspection, i.e., It is above-mentioned to be closed with keyset, and if so, continuing to traverse, otherwise, key is added in used_keys, has marked the key Through being traversed, and ContentDict.get is called to obtain value, returns to value.
The traversal of ContentDict is slower than original dict's, because will create in ergodic process new ContentDict, but deepcopy bring great expense incurred is used in merging data compared to conventional method, traversed These increased expenses can almost be ignored in journey.
In the merging method of nested data provided by the embodiments of the present application, dictionary data structure ContentDict is pair The packaging of existing dictionary realizes the interface function of dictionary, and in a preferred embodiment, which includes Following sections: dictionary array (dict_list) whether there is custom dictionaries (has_self_dict), delete key set (key_del).In addition, traversal interface (iter) can generate an Iterator object, the temporary variable in ergodic process is all deposited It is placed in the Iterator object, as shown in Figure 7.
Dictionary data structure ContentDict provided in an embodiment of the present invention realizes dictionary dict total interface, and It can achieve the time complexity of (1) O, far superior to deepcopy when merging multiple nested dictionary datas;Although Comparing original dictionary in value and traversal has additional expense, but sends one's regards to compared to deepcopy bring performance with interior Topic, this is within the acceptable range.
Corresponding to the merging method of the nested data in above-described embodiment, the present embodiment also provides a kind of nested data Merging device, wherein nested data include multiple dictionary datas, and dictionary data includes reference and quotes corresponding data, Quoting corresponding data includes at least one key-value pair, and key-value pair includes key and key assignments.Shown in Figure 8, above-mentioned apparatus includes: Reference obtains module 82, reference deposit module 84 and merging data and obtains module 86, wherein the function of modules is as follows:
Reference obtains module 82, for obtaining the corresponding reference of each dictionary data in nested data;Reference deposit Module 84, for the priority orders according to dictionary data, the word for the dictionary data structure that each reference deposit is constructed in advance In allusion quotation array;Merging data obtains module 86, for the dictionary array application dictionary key assignments inquiry mode for having reference or Dictionary traverses mode, obtains the corresponding merging data of nested data.
In a kind of wherein possible embodiment, above-mentioned reference is stored in module 84, is also used to according to the excellent of dictionary data Each reference is stored in the dictionary array of the dictionary data structure constructed in advance by the sequence of first grade from low to high one by one.
In alternatively possible embodiment, above-mentioned merging data obtains module 86, is also used to: by each dictionary data Including key be used as current key one by one, following steps are performed both by each current key: according to it is each reference in dictionary array Tandem finds the corresponding key assignments of current key from quoting in corresponding data;It is raw according to each key and its corresponding key assignments At the corresponding merging data of nested data.
In alternatively possible embodiment, above-mentioned merging data obtains module 86, is also used to: whether judging current key It is present in the corresponding data of the reference currently traversed, and judges whether the corresponding key assignments of current key is dictionary;If current Key is present in the corresponding data of the reference currently traversed, and the current corresponding key assignments of key is not dictionary, and key assignments is determined as working as The key assignments of preceding key;If current key is present in the corresponding data of the reference currently traversed, and the current corresponding key assignments of key is word The corresponding dictionary of current key is added in ephemeral data buffer structure by allusion quotation, continues to traverse the corresponding data of remaining reference, until All references traversal is completed, by the dictionary in ephemeral data buffer structure, as the corresponding key assignments of current key.
In alternatively possible embodiment, above-mentioned merging data obtains module 86, is also used to: corresponding for each key Key assignments, execute following screening step: judging in the corresponding key assignments of key whether to include multiple dictionaries, and include in multiple dictionaries Identical key;If so, retain in multiple dictionaries the key of the highest priority of the corresponding dictionary data of dictionary belonging to key and its Key assignments;By after screening step key and its corresponding key assignments merge, obtain the corresponding merging data of nested data.
In alternatively possible embodiment, above-mentioned dictionary data structure further include: delete key set;Wherein, it deletes Deleted key is preserved in keyset conjunction;Above-mentioned merging data obtains module 86, is also used to: judging that current key whether there is in deletion During keyset closes;If it does not, executing the step for judging that current key whether there is in the corresponding data of reference currently traversed.
In alternatively possible embodiment, above-mentioned merging data obtains module 86, is also used to: judging dictionary data knot Custom dictionaries in structure whether there is;If it does, by the dictionary setting in ephemeral data buffer structure to dictionary array end In the custom dictionaries of tail;If it does not, creating new custom dictionaries, at the end of dictionary array to store ephemeral data Dictionary in buffer structure.
In alternatively possible embodiment, above-mentioned merging data obtains module 86, is also used to: key to be deleted is added Enter delete key set;Judge that the custom dictionaries in dictionary data structure whether there is;If it does, deleting in custom dictionaries Key to be deleted.
In alternatively possible embodiment, above-mentioned merging data obtains module 86, is also used to: in dictionary data structure One iterator objects of middle generation, the corresponding data of each reference in traversal dictionary array;Corresponding data are quoted for each, Be performed both by following steps: the key in the corresponding data of reference that judgement currently traverses whether there is in being closed with keyset;If It is that traversal quotes next key in corresponding data;If not, in the key currently traversed is added to being closed with keyset, and Using dictionary key assignments inquiry mode, the corresponding key assignments of the key currently traversed;Based on key each after the completion of traversal and its correspondence Key assignments, generate the corresponding merging data of nested data.
Each word in the merging device of nested data provided in an embodiment of the present invention, first in acquisition nested data The corresponding reference of allusion quotation data, then according to the priority orders of dictionary data, the dictionary number that each reference deposit is constructed in advance According in the dictionary array of structure, finally to the dictionary array application dictionary key assignments inquiry mode or dictionary traversal side for having reference Formula, obtains the corresponding merging data of nested data, and the present apparatus is multiple in nested data by storing in dictionary array The mode of the reference of dictionary data, substantially reduces memory overhead, obtains merging data based on the dictionary array for having reference, greatly Ground promotes combined efficiency, reduces performance cost.
The technical effect of the merging device of nested data provided by the embodiments of the present application, realization principle and generation is with before The merging method embodiment for stating nested data is identical, to briefly describe, the embodiment part of the merging device of nested data Place is not referred to, can refer to corresponding contents in the merging method embodiment of aforementioned nested data.
The embodiment of the present application also provides a kind of electronic equipment, as shown in figure 9, be the structural schematic diagram of the electronic equipment, Wherein, which includes processor 91 and memory 90, which is stored with and can be executed by the processor 91 Computer executable instructions, the processor 91 execute the computer executable instructions to realize the merging side of above-mentioned nested data Method.
In the embodiment shown in Fig. 9, which further includes bus 92 and communication interface 93, wherein processor 91, communication interface 93 and memory 90 are connected by bus 92.
Wherein, memory 90 may include high-speed random access memory (RAM, Random AccessMemory), can also It can further include non-labile memory (non-volatile memory), for example, at least a magnetic disk storage.By at least One communication interface 93 (can be wired or wireless) realizes the communication between the system network element and at least one other network element Connection, can be used internet, wide area network, local network, Metropolitan Area Network (MAN) etc..Bus 92 can be ISA (Industry Standard Architecture, industry standard architecture) bus, PCI (Peripheral Component Interconnect, peripheral hardware Component connection standard) (Extended Industry Standard Architecture extends industrial standard by bus or EISA Structure) bus etc..The bus 92 can be divided into address bus, data/address bus, control bus etc..For convenient for indicating, in Fig. 9 only It is indicated with a four-headed arrow, it is not intended that an only bus or a type of bus.
Processor 91 may be a kind of IC chip, the processing capacity with signal.During realization, above-mentioned side Each step of method can be completed by the integrated logic circuit of the hardware in processor 91 or the instruction of software form.Above-mentioned Processor 91 can be general processor, including central processing unit (Central Processing Unit, abbreviation CPU), network Processor (Network Processor, abbreviation NP) etc.;It can also be digital signal processor (Digital Signal Processor, abbreviation DSP), specific integrated circuit (Application Specific Integrated Circuit, referred to as ASIC), field programmable gate array (Field-Programmable Gate Array, abbreviation FPGA) or other are programmable Logical device, discrete gate or transistor logic, discrete hardware components.General processor can be microprocessor or should Processor is also possible to any conventional processor etc..The step of method in conjunction with disclosed in the embodiment of the present application, can direct body Now executes completion for hardware decoding processor, or in decoding processor hardware and software module combine and execute completion.It is soft Part module can be located at random access memory, and flash memory, read-only memory, programmable read only memory or electrically erasable programmable are deposited In the storage medium of this fields such as reservoir, register maturation.The storage medium is located at memory, and processor 91 is read in memory Information, in conjunction with its hardware complete previous embodiment nested data merging method the step of.
The embodiment of the present application also provides a kind of computer readable storage medium, which has Computer executable instructions, the computer executable instructions are when being called and being executed by processor, the computer executable instructions Processor is promoted to realize the merging method of above-mentioned nested data, specific implementation can be found in preceding method embodiment, herein no longer It repeats.
The merging device and electronics of the merging method of nested data, nested data provided by the embodiment of the present application are set Standby computer program product, the computer readable storage medium including storing program code, what said program code included Instruction can be used for executing the merging method of previous methods nested data as described in the examples, and it is real that specific implementation can be found in method Example is applied, details are not described herein.
Unless specifically stated otherwise, the opposite step of the component and step that otherwise illustrate in these embodiments, digital table It is not limited the scope of the application up to formula and numerical value.
It, can be with if the function is realized in the form of SFU software functional unit and when sold or used as an independent product It is stored in the executable non-volatile computer-readable storage medium of a processor.Based on this understanding, of the invention Technical solution substantially the part of the part that contributes to existing technology or the technical solution can be with software in other words The form of product embodies, which is stored in a storage medium, including some instructions use so that One computer equipment (can be personal computer, server or the network equipment etc.) executes each embodiment institute of the present invention State all or part of the steps of method.And storage medium above-mentioned includes: USB flash disk, mobile hard disk, read-only memory (ROM, Read- Only Memory), random access memory (RAM, Random AccessMemory), magnetic or disk etc. is various to deposit Store up the medium of program code.
In the description of the present invention, it should be noted that term " center ", "upper", "lower", "left", "right", "vertical", The orientation or positional relationship of the instructions such as "horizontal", "inner", "outside" be based on the orientation or positional relationship shown in the drawings, merely to Convenient for description the present invention and simplify description, rather than the device or element of indication or suggestion meaning must have a particular orientation, It is constructed and operated in a specific orientation, therefore is not considered as limiting the invention.In addition, term " first ", " second ", " third " is used for descriptive purposes only and cannot be understood as indicating or suggesting relative importance.
Finally, it should be noted that embodiment described above, only a specific embodiment of the invention, to illustrate the present invention Technical solution, rather than its limitations, scope of protection of the present invention is not limited thereto, although with reference to the foregoing embodiments to this hair It is bright to be described in detail, those skilled in the art should understand that: anyone skilled in the art In the technical scope disclosed by the present invention, it can still modify to technical solution documented by previous embodiment or can be light It is readily conceivable that variation or equivalent replacement of some of the technical features;And these modifications, variation or replacement, do not make The essence of corresponding technical solution is detached from the spirit and scope of technical solution of the embodiment of the present invention, should all cover in protection of the invention Within the scope of.Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (12)

1. a kind of merging method of nested data, the nested data include multiple dictionary datas, the dictionary data packet Include reference and the corresponding data of the reference, the corresponding data of the reference include at least one key-value pair, the key-value pair packet Include key and key assignments;It is characterized in that, which comprises
Obtain the corresponding reference of each dictionary data in the nested data;
According to the priority orders of dictionary data, the dictionary number for the dictionary data structure that each reference deposit is constructed in advance In group;
Mode is traversed to the dictionary array application dictionary key assignments inquiry mode or dictionary for having the reference, obtains the nesting The corresponding merging data of type data.
2. the method according to claim 1, wherein according to the priority orders of dictionary data, described in each Quoting the step being stored in the dictionary array of the dictionary data structure constructed in advance includes:
According to the priority sequence from low to high of dictionary data, each reference is stored in the dictionary number constructed in advance one by one According in the dictionary array of structure.
3. the method according to claim 1, wherein to the dictionary array application dictionary key assignments for having the reference Inquiry mode, the step of obtaining the nested data corresponding merging data, comprising:
It regard the key that each dictionary data includes as current key one by one, following steps is performed both by each current key: According to tandem of each reference in the dictionary array, the current key is found from the corresponding data of the reference Corresponding key assignments;
According to each key and its corresponding key assignments, the corresponding merging data of the nested data is generated.
4. according to the method described in claim 3, it is characterized in that, according to suitable before and after each quote in the dictionary array Sequence, the step of corresponding key assignments of the current key is found from the corresponding data of the reference, comprising:
Judge that the current key whether there is in the corresponding data of reference currently traversed, and judges that the current key is corresponding Key assignments whether be dictionary;
If the current key is present in the corresponding data of the reference currently traversed, and the corresponding key assignments of the current key is not The key assignments is determined as the key assignments of the current key by dictionary;
If the current key is present in the corresponding data of the reference currently traversed, and the corresponding key assignments of the current key is word The corresponding dictionary of the current key is added in ephemeral data buffer structure by allusion quotation, continue to traverse it is remaining quote corresponding data, Until all references traversal is completed, by the dictionary in the ephemeral data buffer structure, as the corresponding key assignments of the current key.
5. according to the method described in claim 4, it is characterized in that, generating institute according to each key and its corresponding key assignments The step of stating nested data corresponding merging data, further includes:
For the corresponding key assignments of each key, following screening step is executed:
Judge in the corresponding key assignments of the key whether to include multiple dictionaries, and includes identical key in multiple dictionaries;Such as Fruit is the key and its key assignments for retaining the highest priority of the corresponding dictionary data of dictionary belonging to key in multiple dictionaries;
By after the screening step key and its corresponding key assignments merge, obtain the corresponding merging number of the nested data According to.
6. according to the method described in claim 4, it is characterized in that, the dictionary data structure further include: delete key set;Its In, the delete key set preserves deleted key;
Before judging that the current key whether there is the step in the corresponding data of reference currently traversed, further includes:
Judge that the current key whether there is in the delete key set;
If it does not, executing the judgement current key whether there is the step in the corresponding data of reference currently traversed Suddenly.
7. according to the method described in claim 4, it is characterized in that, the method also includes:
Judge that the custom dictionaries in the dictionary data structure whether there is;
If it does, by the dictionary setting in the ephemeral data buffer structure to the described customized of dictionary array end In dictionary;
If it does not, new custom dictionaries is created at the end of the dictionary array, to store the ephemeral data caching Dictionary in structure.
8. according to the method described in claim 6, it is characterized in that, the method also includes:
The delete key set is added in key to be deleted;
Judge that the custom dictionaries in the dictionary data structure whether there is;
If it does, deleting the key to be deleted in the custom dictionaries.
9. the method according to claim 1, wherein being traversed to the dictionary array application dictionary for having the reference Mode, the step of obtaining the nested data corresponding merging data, comprising:
An iterator objects are generated in the dictionary data structure, traverse the corresponding number of each reference in the dictionary array According to;For the corresponding data of each reference, it is performed both by following steps:
Judge that the key in the corresponding data of reference currently traversed whether there is in being closed with keyset;If so, described in traversal Quote next key in corresponding data;If not, by the key currently traversed be added to it is described closed with keyset, and Using dictionary key assignments inquiry mode, the corresponding key assignments of the key currently traversed;
Based on key each after the completion of traversal and its corresponding key assignments, the corresponding merging data of the nested data is generated.
10. a kind of merging device of nested data, the nested data include multiple dictionary datas, the dictionary data packet Include reference and the corresponding data of the reference, the corresponding data of the reference include at least one key-value pair, the key-value pair packet Include key and key assignments;It is characterized in that, described device includes:
Reference obtains module, for obtaining the corresponding reference of each dictionary data in the nested data;
Reference deposit module, for the priority orders according to dictionary data, the word that each reference deposit is constructed in advance In the dictionary array of allusion quotation data structure;
Merging data obtains module, for the dictionary array application dictionary key assignments inquiry mode or dictionary for having the reference Traversal mode obtains the corresponding merging data of the nested data.
11. a kind of electronic equipment, which is characterized in that including processor and memory, the memory is stored with can be described The computer executable instructions that processor executes, the processor execute the computer executable instructions to realize claim 1 to 9 described in any item methods.
12. a kind of computer readable storage medium, which is characterized in that the computer-readable recording medium storage has computer can It executes instruction, when being called and being executed by processor, computer executable instructions promote to handle the computer executable instructions Device realizes the described in any item methods of claim 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 true CN110516122A (en) 2019-11-29
CN110516122B 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)

Cited By (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 (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050091637A1 (en) * 2003-10-23 2005-04-28 Microsoft Corporation Changeable class and pattern to provide selective mutability in computer programming environments
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

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050091637A1 (en) * 2003-10-23 2005-04-28 Microsoft Corporation Changeable class and pattern to provide selective mutability in computer programming environments
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
_BINGOHE: ""无限遍历,Python实现在多维嵌套字典、列表、元组的JSON中获取数据"", 《HTTPS://WWW.CNBLOGS.COM/DETECTOR/P/8085460.HTML》 *
Z小旋: ""Python中变量在内存的存储与地址变化详解(深浅拷贝,值/引用传递、可变不可变数据类型)"", 《HTTPS://BLOG.CSDN.NET/AS480133937/ARTICLE/DETAILS/87305247》 *
佚名: ""通过数据值引用保存数据并减少数据副本"", 《HTTPS://ZONE.NI.COM/REFERENCE/ZHS-XX/HELP/371361R-0118/LVCONCEPTS/EXTERNAL_DATA_VAL_REF/》 *

Cited By (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

Also Published As

Publication number Publication date
CN110516122B (en) 2022-05-13

Similar Documents

Publication Publication Date Title
Mucke Shapes and implementations in three-dimensional geometry
CN104866497B (en) The metadata updates method, apparatus of distributed file system column storage, host
CN103326732B (en) The method of compression data, the decompression method of data, encoder
CN110019292B (en) Data query method and device
US10068033B2 (en) Graph data query method and apparatus
CN109145158A (en) The processing method and Bloom filter of data in a kind of Bloom filter
CN108681572A (en) Date storage method, device and the electronic equipment of block chain
WO2016209975A2 (en) Preliminary ranker for scoring matching documents
CN109564545A (en) Method and apparatus for compressing address
CN107209714A (en) The control method of distributed memory system and distributed memory system
CN106919678A (en) A kind of database inquiry optimization system and method
EP2858024A1 (en) An asset management device and method in a hardware platform
EP3314468A1 (en) Matching documents using a bit vector search index
CN112148217B (en) Method, device and medium for caching deduplication metadata of full flash memory system
CN109727070A (en) A kind of determination method and device of potential any active ues
CN106250061A (en) File download processing method and processing device
CN105159927B (en) Method and device for selecting subject term of target text and terminal
CN110399096A (en) Metadata of distributed type file system caches the method, apparatus and equipment deleted again
CN114327917A (en) Memory management method, computing device and readable storage medium
CN110516122A (en) Embedded data merging method and device and electronic equipment
CN109086462A (en) The management method of metadata in a kind of distributed file system
CN105447004B (en) The excavation of word, relevant inquiring method and device are recommended in inquiry
CN107133183A (en) A kind of cache data access method and system based on TCMU Virtual Block Devices
CN110457535A (en) Hash bucket lookup method, Hash table storage, Hash table lookup method and device
CN109558159A (en) The update method and device of user interface in game

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