A method for traversing data in a virtual machine and related apparatus
By using a pre-defined iteration helper class in the virtual machine to build the target iteration component, adapting the container class and defining member variables, the problem of needing to write different interfaces for different template parameters is solved, and efficient data traversal is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WUHAN DOUYU NETWORK TECHNOLOGY CO LTD
- Filing Date
- 2021-05-08
- Publication Date
- 2026-07-03
AI Technical Summary
In existing technologies, when traversing map objects in a virtual machine, different interfaces need to be written for different template parameters, which increases the amount of code development required by developers.
The target iterative component is constructed by using a pre-defined iterative helper class to adapt to container classes in the virtual machine. Member variables are defined to store key and value data, and iterative methods are implemented through a pre-defined loop interface to achieve a unified access method for iterators.
It reduces the workload of developers in writing interfaces, maintains consistency in iteration, and improves traversal efficiency.
Smart Images

Figure CN115309495B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and related apparatus for traversing data in a virtual machine. Background Technology
[0002] In existing technologies, when iterating over map objects in a virtual machine, a situation arises where a separate interface needs to be written for each type of virtual machine object for iteration. Since a map object has two template parameters—one for the key and one for the value—in actual development, if developers define different template parameters, different interfaces need to be written for iteration.
[0003] For example, vmap<vstring,int> vmap1; The vmap1 object is an object with vstring as the key and int as the value. A method needs to be written to iterate over it.
[0004] vmap<vstring,vstring> vmap2; and the vmap2 object is an object with vstring as the key and vstring as the value, so another method needs to be written to iterate over it.
[0005] Since the program will definitely define many similar map objects of different types, it will cause the amount of code development work for developers to increase dramatically. Summary of the Invention
[0006] The purpose of this invention is to provide a method for traversing data in a virtual machine, which alleviates the technical problem in the prior art that different interfaces need to be written for traversing data in a virtual machine when facing different template parameters.
[0007] In a first aspect, the present invention provides a method for traversing data in a virtual machine, comprising the following steps: constructing a target iteration component through a preset iteration auxiliary class, wherein the target iteration component is adapted to the virtual machine's method for iterating data in the virtual machine, and the preset iteration auxiliary class corresponds to a container class in the virtual machine;
[0008] The elements of the data in the virtual machine are obtained based on the target iterative component, wherein the elements include key data and value data;
[0009] The member variables in the application layer iterator are assigned values based on the key data and the value data, so that the application layer iterator can traverse the data in the virtual machine through a preset loop interface. The member variables include member variables for storing key data and member variables for storing value data.
[0010] Preferably, the step of constructing a target iteration component through a preset iteration helper class, wherein the target iteration component adapts to the virtual machine's iteration method for data in the virtual machine, and the preset iteration helper class corresponds to a container class in the virtual machine, further includes:
[0011] Define a preset template class, wherein the preset template class can import objects of different specific types;
[0012] Define member variables of the preset template class, wherein the member variables store the corresponding auxiliary utility class and data for iteration, and the different auxiliary utility classes can implement different traversal methods;
[0013] The constructor of the preset template class is stored in the member variable to generate the basic iterative component.
[0014] Preferably, the step of constructing a target iteration component through a preset iteration helper class, wherein the target iteration component adapts to the virtual machine's method for iterating data in the virtual machine, and the preset iteration helper class corresponds to a container class in the virtual machine, includes:
[0015] A preset iteration helper class corresponding to the data in the virtual machine is determined based on the data in the virtual machine. The preset iteration helper class corresponds to the container class in the virtual machine. The preset iteration helper class has two template parameters, including a key template parameter and a value template parameter.
[0016] Construct an initial iteration component based on the preset iteration auxiliary class and the basic iteration component;
[0017] Determine the preset iteration class corresponding to the data in the virtual machine based on the data in the virtual machine;
[0018] The target iteration component is generated based on the preset iteration class and the initial iteration component.
[0019] Preferably, the step of generating the target iteration component based on the preset iteration class and the initial iteration component includes:
[0020] The target iteration component is generated based on the preset iteration class and the initial iteration component through inheritance.
[0021] Preferably, the step of obtaining elements of data in the virtual machine based on the target iteration component, wherein the elements include key data and value data, includes:
[0022] Based on the target iterative component, a preset interface is defined. The preset interface is used to obtain the element corresponding to the data in the virtual machine according to the key template parameter and the value template parameter.
[0023] Preferably, before the step of assigning values to member variables in the application-layer iterator based on the key data and the value data, so that the application-layer iterator can traverse the data in the virtual machine through a preset loop interface, wherein the member variables include member variables for storing key data and member variables for storing value data, the method further includes:
[0024] Define a preset access interface, which corresponds to the iteration type of the data in the virtual machine. The preset access interface can obtain the target iteration component corresponding to the first element of the data in the virtual machine and the termination iteration component corresponding to the data in the virtual machine.
[0025] Preferably, the method further includes:
[0026] Through the function:
[0027] Iterator<VMap.Entry> iter;
[0028] The virtual machine's iteration method is mapped to C++, where the Iterator...<VMap.Entry> `iter;` is a definition statement that defines the target iterator component as a member variable.
[0029] A second aspect of this application provides a data traversal device in a virtual machine, comprising: a construction module, configured to construct a target iteration component through a preset iteration auxiliary class, wherein the target iteration component is adapted to the virtual machine's method for iterating data in the virtual machine, and the preset iteration auxiliary class corresponds to a container class in the virtual machine;
[0030] The value retrieval module is used to obtain elements of data in the virtual machine based on the target iterative component, wherein the elements include key data and value data;
[0031] The assignment module is used to assign values to member variables in the application layer iterator based on the key data and the value data, so that the application layer iterator can traverse the data in the virtual machine through a preset loop interface. The member variables include member variables for storing key data and member variables for storing value data.
[0032] A third aspect of this application provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor is configured to execute the computer program stored in the memory to implement the steps of the virtual machine data traversal method described above.
[0033] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the data traversal method in a virtual machine as described above.
[0034] This invention provides a method and related apparatus for traversing data in a virtual machine. It constructs a target iteration component by using a preset iteration auxiliary class. This target iteration component adapts to the virtual machine's data iteration methods, and the preset iteration auxiliary class corresponds to a container class in the virtual machine. It ensures that the iterator access method provided to C++ is consistent with the original C++ iterator access method. Furthermore, it defines two template parameters: one for storing the data and the other for using an auxiliary utility class to traverse this template parameter. By separating the data storage and traversal methods, different traversal methods can be implemented by passing in different auxiliary utility classes externally. By using a preset iteration auxiliary class corresponding to various container traversal auxiliary classes, it can adapt to all container classes in the virtual machine. The target iterative component retrieves elements of the data in the virtual machine, where each element includes key data and value data. Based on the key data and value data, member variables in the application-layer iterator are assigned values, allowing the application-layer iterator to traverse the data in the virtual machine through a preset loop interface. This maps the virtual machine's iteration method to C++, so C++ doesn't need to concern itself with how the iteration occurs in the virtual machine; it automatically converts the C++ iteration to the virtual machine's iteration. The member variables include those for storing key data and those for storing value data. The `Next()` function, obtained through the preset loop interface, stores the next element of the virtual machine data in the `key` and `value` member variables. The C++ object then retrieves the corresponding values from the `key` and `value` member variables using previously written functionality and returns them to the C++ object. Thus, C++ continuously retrieves data from the virtual machine using the `next()` function. This clever storage of elements in member variables allows C++ to use its iterator to access elements, maintaining iteration consistency. Attached Figure Description
[0035] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0036] Figure 1 A flowchart of a data traversal method in a virtual machine provided by an embodiment of the present invention;
[0037] Figure 2 A schematic diagram illustrating an embodiment of a data traversal device in a virtual machine provided by an embodiment of the present invention;
[0038] Figure 3 A schematic diagram illustrating an embodiment of an electronic device provided in this application;
[0039] Figure 4 This is a schematic diagram illustrating an embodiment of a computer-readable storage medium provided in this application. Detailed Implementation
[0040] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0041] The terms "comprising" and "having," and any variations thereof, used in the embodiments of this invention are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the steps or units listed, but may optionally include other steps or units not listed, or may optionally include other steps or units inherent to such processes, methods, products, or devices.
[0042] An embodiment of the present invention provides a method for traversing data in a virtual machine, comprising the following steps:
[0043] S101. Construct a target iteration component through a preset iteration helper class, wherein the target iteration component is adapted to the virtual machine's iteration method for data in the virtual machine, and the preset iteration helper class corresponds to the container class in the virtual machine;
[0044] In one possible implementation, the step of constructing a target iteration component through a preset iteration helper class, wherein the target iteration component adapts to the virtual machine's method for iterating data in the virtual machine, and the preset iteration helper class corresponds to a container class in the virtual machine, further includes:
[0045] Define a preset template class, wherein the preset template class can import objects of different specific types;
[0046] Define member variables of the preset template class, wherein the member variables store the corresponding auxiliary utility class and data for iteration, and the different auxiliary utility classes can implement different traversal methods;
[0047] The constructor of the preset template class is stored in the member variable to generate the basic iterative component.
[0048] For example, a base iterator is constructed, which provides a way for C++ to access it. The base iterator interface is the same as the existing iterator model in C++, so that iteration in the virtual machine can be accessed using the C++ model. The base iterator encapsulates the same interface and access methods as existing iterators.
[0049] The specific design is as follows:
[0050] Design template class:
[0051] Through function:
[0052] template<typename T,typename V>
[0053] Design a template class that can accept objects of different concrete types.
[0054] class ItBase{The name of the template class ItBase is the base class of the basic iterator.
[0055] Design the member variables of the template class ItBase:
[0056] T utils_; Design a member variable to store the corresponding iterative utility class, which is a template parameter.
[0057] V data_; Design a member variable to store the corresponding data, which is a template parameter.
[0058] The constructor needs to be passed in an auxiliary utility class that requires iteration:
[0059] Define two template parameters: one is a template parameter used to store its data, and the other is an auxiliary utility class used to iterate over this template parameter.
[0060] By separating the data storage and traversal methods, different traversal methods can be implemented by passing in different auxiliary utility classes from the outside.
[0061] Design the constructor for ItBase.
[0062] Through function:
[0063] ItBase(T data):data_(data){}
[0064] Store the basic iterator in a member variable.
[0065] Design an interface for transmitting a pre-defined loop interface for iterative data:
[0066] Through function statements:
[0067] ItBase&operator++(){
[0068] The interface is designed to overload the ++ operator, so that when iterating over virtual machine objects, the next element can be obtained by using ++ in the same way as in C++.
[0069] Through function statements:
[0070] data_ = utils_->Next();
[0071] The next data is obtained through the Next interface of the helper class and stored in the member variable data_.
[0072] Through function statements:
[0073] const V*operator->()const{return&data_;}
[0074] The specific data can be obtained by overloading the -> operator.
[0075] The iterator described above provides an interface for iteration in C++, mainly including operator++ to get the next element and operator-> to get the data.
[0076] The above interfaces are the ones that will be used later during the traversal, and they are also the most frequently used interfaces. The above preset loop interfaces are the same as those for C++ object variables.
[0077] In one possible implementation, the step of constructing a target iteration component through a preset iteration helper class, wherein the target iteration component adapts to the virtual machine's method for iterating data in the virtual machine, and the preset iteration helper class corresponds to a container class in the virtual machine, includes:
[0078] A preset iteration helper class corresponding to the data in the virtual machine is determined based on the data in the virtual machine. The preset iteration helper class corresponds to the container class in the virtual machine. The preset iteration helper class has two template parameters, including a key template parameter and a value template parameter.
[0079] Construct an initial iteration component based on the preset iteration auxiliary class and the basic iteration component;
[0080] Determine the preset iteration class corresponding to the data in the virtual machine based on the data in the virtual machine;
[0081] The target iteration component is generated based on the preset iteration class and the initial iteration component.
[0082] For example, we can design a C++ helper class corresponding to iteration in the virtual machine to implement the functionality of the aforementioned preset loop interface, specifically including a Next function. Details are as follows:
[0083] Design template types:
[0084] Through function statements:
[0085] template<typename K,typename V>
[0086] struct MapUtils{
[0087] The template type described above is an iteration helper class designed for vmap, which has two template parameters: one for the key and one for the value.
[0088] The MapUtils type subsequently corresponds to the utils_ of ItBase mentioned above.
[0089] Template classes provide the specific methods for iterating over elements. This example only implements an iteration helper class designed for vmap. However, based on the design presented here, an iteration helper class for linked lists can also be implemented. Therefore, the design presented here makes it easy to implement iteration helper classes for various containers, thus adapting to all container classes in virtual machines.
[0090] Design a pre-defined loop interface and retrieve the content of the next element:
[0091] V next(){
[0092] jfieldID kid=GetFieldID(jcls,"key","Object");
[0093] jfieldID vid=GetFieldID(jcls,"value","Object");
[0094] This involves retrieving the key and value attributes of a class, which correspond to the two attribute data of the class. The object attribute corresponds to the general data type in the virtual machine, which is a generic type that can correspond to any data type.
[0095] Once you have the method, you can call it to retrieve the corresponding data.
[0096] Object k = GetObjectField(kid); retrieves the corresponding value of k.
[0097] Object v = GetObjectField(vid); retrieves the corresponding value of v.
[0098] After obtaining the keys and values, they can be combined into a result data.
[0099] Use the std::make_pair function to combine it into a key-value pair.
[0100] Return std::make_pair<k,v> (k,v);} returns the result data.
[0101] This interface is used to retrieve the next element of the vmap in the virtual machine. This interface is designed to facilitate subsequent iterations, where the C++ functionality will call this interface to retrieve the next element.
[0102] In one possible implementation, the step of generating the target iteration component based on the preset iteration class and the initial iteration component includes:
[0103] The target iteration component is generated based on the preset iteration class and the initial iteration component through inheritance.
[0104] For example, we design a corresponding C++ wrapper to correspond to the iteration type in the virtual machine. It also provides an access interface for vmap iteration, i.e., a default access interface. This encapsulation is done through a class. In the steps above, a base class for iterators, namely the base iterator, is defined; it is a generic iterator class.
[0105] We need to design an iterator class that can access vmap for iterating over vmap.
[0106] template<typename K,typename V>
[0107] struct CMapIterator:publicIterator<K,V> {}
[0108] The iteration of vmap is designed as a CMapIterator iterator by inheriting from the previous Iterator iterator.
[0109] In one possible implementation, before the step of assigning values to member variables in the application-layer iterator based on the key data and the value data, so that the application-layer iterator traverses the data in the virtual machine through a preset loop interface, wherein the member variables include member variables for storing key data and member variables for storing value data, the method further includes:
[0110] Define a preset access interface, which corresponds to the iteration type of the data in the virtual machine. The preset access interface can obtain the target iteration component corresponding to the first element of the data in the virtual machine and the termination iteration component corresponding to the data in the virtual machine.
[0111] For example, we design a C++ wrapper to correspond to the iteration type in the virtual machine. It also provides an access interface for vmap iteration. Specifically, this encapsulation is done through a class:
[0112] template<typename K,typename V>
[0113] struct CMap{
[0114] This class requires two template parameters, one for the key and one for the value.
[0115] Two interfaces are provided for traversal.
[0116] Through function statements:
[0117] ItBase begin()const{
[0118] The interface is used to obtain an iterator for the first element in a CMP object.
[0119] Returns an iterator to the first element of this object. Since ItBase is the iterator, an instance of this object needs to be created and a cmap object passed into it.
[0120] CMapIterator<K,V> The template parameters K and V need to be provided to the corresponding template parameters of CMapIterator. Since the object is cmap, the corresponding CMapIterator iterator is instantiated.
[0121] It implements an iterator that returns a map object.
[0122] Through function statements:
[0123] ItBase end()const; {
[0124] The interface is used to retrieve the iterator to the tail of the CMP object, i.e., the end marker. Since it is an end marker, returning an empty ItBase object can be used as the end marker.
[0125] Return CMapIterator<K,V> (this);}
[0126] Returns a corresponding template parameter K and V, and passes the this pointer into it.
[0127] Two template parameters are defined: one to store the data, and the other to iterate over this template parameter. By separating the data storage and iteration methods, different iteration methods can be implemented by passing in different external helper classes.
[0128] S102. Obtain elements of data in the virtual machine based on the target iterative component, wherein the elements include key data and value data;
[0129] In one possible implementation, the step of obtaining elements of data in the virtual machine based on the target iterative component, wherein the elements include key data and value data, includes:
[0130] Based on the target iterative component, a preset interface is defined. The preset interface is used to obtain the element corresponding to the data in the virtual machine according to the key template parameter and the value template parameter.
[0131] By storing elements in member variables, C++ can use its iterators to retrieve elements, thus maintaining iteration consistency.
[0132] S103. Assign values to member variables in the application layer iterator based on the key data and the value data, so that the application layer iterator can traverse the data in the virtual machine through a preset loop interface, wherein the member variables include member variables for storing key data and member variables for storing value data.
[0133] In one possible implementation, the method further includes:
[0134] Through the function:
[0135] Iterator<VMap.Entry> iter;
[0136] The virtual machine's iteration method is mapped to C++, where the Iterator...<VMap.Entry> `iter;` is a definition statement, where `iter` is the target iterator component, `Iterator` is a C++ iterator, and `VMap.Entry` is a VMap object parameter, defining the target iterator component as a member variable.
[0137] For example, through function statements:
[0138] class VMapIterator
[0139] Iterator<VMap.Entry> iter;
[0140] Object Key;
[0141] Object value;
[0142] VMapIterator(VMap map){
[0143] iter = map.iterator();
[0144] boolean Next(){
[0145] Map.Entry entry=iter.next();
[0146] key = entry.getKey();
[0147] Value = entry.getValue();
[0148] Wherein, class VMapIterator represents the iteration of vmap data in the virtual machine corresponding to the target iterator, where vmap data is data in the virtual machine, and the Iterator...<VMap.Entry> `iter;` is a definition statement that defines the target iterator as a member variable. `Object Key` represents a member variable used to store value data, and `Object value` represents a member variable used to store key data. `VMapIterator(VMap map)` is a function statement that imports the data from `vmap`. `iter = map.iterator();` is a function statement based on the target iterator component as a member variable. `boolean Next()` is a function statement that retrieves the next data according to a preset loop interface. `Map.Entry entry = iter.next()` is a function statement that retrieves the iterator for the next data. `key = entry.getKey();` retrieves the corresponding key and assigns it to the member variable for storage. `Value = entry.getValue();` retrieves the corresponding value and assigns it to the member variable for storage.
[0149] In one possible implementation, for example, a vmap exists in the virtual machine.<vstring,vstring> An object like `vmaptest` has `vstring` as its key and value type. The method for iterating through it is as follows:
[0150] The for loop iterates through vmaptest.
[0151] Iter->first is the key of the first element retrieved.
[0152] Iter->second is the value of the first element retrieved.
[0153] This pattern allows iterating over vmap objects in the virtual machine in the same way as iterating over map objects in C++. The iterator `iter` in the loop is the iterator for the map object, thus providing the functionality to retrieve the key and value, as well as the ability to get the next element. This ensures that iterating over vmaptest is identical to iterating over other C++ objects, guaranteeing that all previously written functionality can be reused on virtual machine objects, thereby significantly reducing the amount of code required for feature development.
[0154] A target iteration component is constructed by pre-defined iteration helper classes. This target iteration component adapts to the virtual machine's iteration methods for data within the virtual machine, and the pre-defined iteration helper classes correspond to container classes within the virtual machine. This ensures that the iterator access methods provided to C++ are consistent with existing C++ iterator access methods. Furthermore, two template parameters are defined: one for storing the data and the other for traversing this template parameter. By separating data storage and traversal methods, different traversal methods can be implemented by passing in different helper classes externally. By using pre-defined iteration helper classes corresponding to various container traversal helper classes, it can adapt to all container classes within the virtual machine. The target iterative component retrieves elements of the data in the virtual machine, where each element includes key data and value data. Based on the key data and value data, member variables in the application-layer iterator are assigned values, allowing the application-layer iterator to traverse the data in the virtual machine through a preset loop interface. This maps the virtual machine's iteration method to C++, so C++ doesn't need to concern itself with how the iteration occurs in the virtual machine; it automatically converts the C++ iteration to the virtual machine's iteration. The member variables include those for storing key data and those for storing value data. The `Next()` function, obtained through the preset loop interface, stores the next element of the virtual machine data in the `key` and `value` member variables. The C++ object then retrieves the corresponding values from the `key` and `value` member variables using previously written functionality and returns them to the C++ object. Thus, C++ continuously retrieves data from the virtual machine using the `next()` function. This clever storage of elements in member variables allows C++ to use its iterator to access elements, maintaining iteration consistency. If we do not adopt this solution and instead use existing technology, we will face the problem that when developers define different template parameters, we need to write different interfaces to traverse them. This will make it impossible to uniformly process the objects that need to be traversed, which will increase the workload of developers and reduce the efficiency of traversal.
[0155] Please see Figure 2 In one embodiment of the data traversal device in the virtual machine in this application, the image display device includes:
[0156] The construction module 201 is used to construct a target iteration component through a preset iteration auxiliary class, wherein the target iteration component is adapted to the virtual machine's iteration method for data in the virtual machine, and the preset iteration auxiliary class corresponds to a container class in the virtual machine;
[0157] The value retrieval module 202 is used to obtain elements of data in the virtual machine based on the target iterative component, wherein the elements include key data and value data;
[0158] The assignment module 203 is used to assign values to member variables in the application layer iterator based on the key data and the value data, so that the application layer iterator can traverse the data in the virtual machine through a preset loop interface. The member variables include member variables for storing key data and member variables for storing value data.
[0159] Please see Figure 3 , Figure 3 A schematic diagram illustrating an embodiment of the electronic device provided in this application.
[0160] like Figure 3 As shown, this application embodiment provides an electronic device, including a memory 310, a processor 320, and a computer program 311 stored in the memory 310 and executable on the processor 320. When the processor 320 executes the computer program 311, it performs the following steps: constructing a target iteration component through a preset iteration auxiliary class, wherein the target iteration component is adapted to the virtual machine's iteration method for data in the virtual machine, and the preset iteration auxiliary class corresponds to a container class in the virtual machine; obtaining elements of the data in the virtual machine based on the target iteration component, wherein the elements include key data and value data; assigning values to member variables in an application-layer iterator based on the key data and the value data, so that the application-layer iterator traverses the data in the virtual machine through a preset loop interface, wherein the member variables include member variables for storing key data and member variables for storing value data.
[0161] like Figure 4 As shown, this application embodiment provides a computer-readable storage medium 400 storing a computer program 411. When executed by a processor, the computer program 411 implements the following: constructing a target iteration component through a preset iteration auxiliary class, wherein the target iteration component is adapted to the virtual machine's method for iterating over data in the virtual machine, and the preset iteration auxiliary class corresponds to a container class in the virtual machine; obtaining elements of the data in the virtual machine based on the target iteration component, wherein the elements include key data and value data; assigning values to member variables in an application-layer iterator based on the key data and the value data, so that the application-layer iterator traverses the data in the virtual machine through a preset loop interface, wherein the member variables include member variables for storing key data and member variables for storing value data.
[0162] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0163] For example, the above division of units is merely a logical functional division; in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual couplings, direct couplings, or communication connections may be indirect couplings or communication connections through some communication interfaces, devices, or units, and may be electrical, mechanical, or other forms.
[0164] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0165] In addition, the functional units in the embodiments provided by the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0166] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0167] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0168] Finally, it should be noted that the above embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the scope of the technology disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention. All should be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for traversing data in a virtual machine, the method comprising: Includes the following steps: A target iteration component is constructed by means of a preset iteration helper class, wherein the target iteration component is adapted to the virtual machine's method of iterating over data in the virtual machine, and the preset iteration helper class corresponds to the container class in the virtual machine; The elements of the data in the virtual machine are obtained based on the target iterative component, wherein the elements include key data and value data; The member variables in the application layer iterator are assigned values based on the key data and the value data, so that the application layer iterator can traverse the data in the virtual machine through a preset loop interface. The member variables include member variables for storing key data and member variables for storing value data. The method also includes: using the function: Iterator<VMap.Entry> iter; maps the virtual machine's iteration methods to C++, where the Iterator...<VMap.Entry> `iter;` is a definition statement, where `iter` is the target iterator component, `Iterator` is a C++ iterator, and `VMap.Entry` is a VMap object parameter, defining the target iterator component as a member variable. The step of constructing a target iteration component through a preset iteration helper class, wherein the target iteration component adapts to the virtual machine's iteration method for data in the virtual machine, and the preset iteration helper class corresponds to a container class in the virtual machine, further includes: Define a preset template class, wherein the preset template class can import objects of different specific types; Define member variables of the preset template class, wherein the member variables store the corresponding auxiliary utility class and data for iteration, and different auxiliary utility classes can implement different traversal methods; The constructor function of the preset template class is stored in the member variable to generate the basic iterative component; The step of constructing a target iteration component through a preset iteration helper class, wherein the target iteration component adapts to the virtual machine's method for iterating data in the virtual machine, and the preset iteration helper class corresponds to a container class in the virtual machine, includes: A preset iteration helper class corresponding to the data in the virtual machine is determined based on the data in the virtual machine. The preset iteration helper class corresponds to the container class in the virtual machine. The preset iteration helper class has two template parameters, including a key template parameter and a value template parameter. Construct an initial iteration component based on the preset iteration auxiliary class and the basic iteration component; Determine the preset iteration class corresponding to the data in the virtual machine based on the data in the virtual machine; Generate a target iteration component based on the preset iteration class and the initial iteration component; The step of generating the target iteration component based on the preset iteration class and the initial iteration component includes: The target iteration component is generated based on the preset iteration class and the initial iteration component through inheritance. Before the step of assigning values to member variables in the application-layer iterator based on the key data and the value data, so that the application-layer iterator traverses the data in the virtual machine through a preset loop interface, wherein the member variables include member variables for storing key data and member variables for storing value data, the method further includes: Define a preset access interface, which corresponds to the iteration type of the data in the virtual machine. The preset access interface can obtain the target iteration component corresponding to the first element of the data in the virtual machine and the termination iteration component corresponding to the data in the virtual machine.
2. The method of claim 1, wherein, The step of obtaining elements of data in the virtual machine based on the target iterative component, wherein the elements include key data and value data, includes: Based on the target iterative component, a preset interface is defined. The preset interface is used to obtain elements corresponding to the data in the virtual machine according to the key template parameters and value template parameters.
3. An electronic device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor, when executing the computer program stored in the memory, implements the steps of a method for traversing data in a virtual machine as claimed in any one of claims 1-2.
4. A computer readable storage medium having stored thereon a computer program, characterized in that: When the computer program is executed by the processor, it implements the steps of the method for traversing data in the virtual machine as described in any one of claims 1-2.