This application is based upon and claims the benefit of priority of the prior Japanese Patent Application No. 2017-25401, filed on Feb. 14, 2017, the entire contents of which are incorporated herein by reference.
The embodiments discussed herein are related to a method of storing data, an information processing apparatus and a non-transitory computer-readable storage medium.
In a case where plural types of data is sorted for each type and stored, a storage area (hereinafter, referred to as management area) storing information, which is referred to during the sorting, may be used separately from an area storing the data itself.
However, in a case where a large amount of data is processed, by preparing not only an area for storing the data itself but also a management area, the storage area of a system is occupied, which may affect the performance of other processes. In addition, in a case of a system (for example, embedded system) in which usable physical resources are limited, a process may not be performed due to an insufficient storage area. As related art of Patent Document 1, there is Japanese Laid-open Patent Publication No. 11-167508. Also, as related art of non-Patent Document 1, there is Bing-Chao Huang, Michael A. Langston, “Fast Stable Merging and Sorting in Constant Extra Space”, The Computer Journal, Oxford University Press, Dec. 1, 1992, volume 35, No. 6, pp. 643-650.
According to an aspect of the invention, a method of storing target data into a data storage area by a computer, the target data including a plurality of types of data, the method includes acquiring first information indicating a number of data piece of each of the plurality of types of data included in the target data, and second information indicating an priority order of the plurality of types of data in the target data, storing, in a management area within the data storage area, third information indicating an area defined based on the first information and the second information within the data storage area, each data piece of the plurality of types of data being to be stored in the area indicated by the third information, specifying a storage position of first data of the plurality of types of data included in the target data by referring to the third information in accordance with a type of the first data, storing the first data in the specified storage position when second data of the plurality of types of data different from the first data is not stored in the specified storage position, and storing the first data in a position in at least one of the management area in which the third information corresponding to the type of the first data is stored and the specified storage position, based on comparison between the priority order of a type of the second data and the priority order of the type of the first data, when the second data is stored in the specified storage position.
The object and advantages of the invention will be realized and attained by means of the elements and combinations particularly pointed out in the claims.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory and are not restrictive of the invention, as claimed.
In the following, input data values are sorted for each key and the sorted data values are stored in a data storage area. For example, as illustrated in
By storing data values in this manner, it is possible to perform post-processing (for example, data mining, retrieval, and the like) at high speed.
Note that the following conditions are satisfied.
(1) Distribution of data values (the number of data values, hereinafter, referred to as kn) for each key is found in advance.
(2) The data values are input one by one.
(3) The data values are sorted and stored for each key in the data storage area.
(4) For each key, the data values are stored in accordance with input order.
In a case of an example of
The data values may be directly stored in the data storage area, but as illustrated in
By using
As illustrated in
As illustrated in
Then, as illustrated in
According to the first method, it is possible to perform a process of sorting and storing the input data values for each key. However, since the size of the management area increases as the number of keys increases, the first method is not suitable for a case where the number of types of the data values is large.
By using
As illustrated in
In the second method, the pointer to be used in a subsequent processing may be overwritten with the input data value. For example, as illustrated in
By using
As illustrated in
The storage process proceeds basically in the same manner as that of the second method. For example, in a case where the data value “a2” is input in a state illustrated in
Then, as illustrated in
Furthermore, as illustrated in
However, by the third method, the last data value or the first data value of each key is overwritten, and it is hard to store the entire data value.
As described above, by the first to third methods, it is hard to appropriately store the data value. Accordingly, in the embodiment, the data value is stored by the following method.
In
The head specifying unit 101 performs a process for specifying the head position for each key based on data stored in the input data storage unit 111. The storage processing unit 103 stores input data stored in the input data storage unit 111 in the data storage unit 113 based on a result of the process by the head specifying unit 101. The data storage area including the management area is included in the data storage unit 113. The rearrangement unit 105 performs a process based on data stored in the data storage unit 113, and stores the processed result in the output data storage unit 115.
Next, by using
However, in the embodiment, similar to the third method, the pointer indicating the head position of a case where (kn−1) for each key is acquired and (kn−1) data values are sorted and stored is stored in the management area. Here, X[3] and X[6] are focused. In a case of performing the third method, as illustrated in
Therefore, in a case where the data value is already stored in the storage position X[i] (1≤i≤9) indicated by the pointer, one of the input data value and the data value stored in X[i] is the last data value of a corresponding key (key “k”) and the other data value is the first data value of a key in the position after the key “k” in the order. It is assumed that this property is property (1).
In addition, in a case where the last data value of a certain key is stored, an area storing the pointer for the key in the management area is not referred to the post-processing. It is assumed that this property is property (2).
In view of these property (1) and property (2), in the embodiment, in a case where the data value is already stored in the storage position indicated by the pointer X[i], the last data value among the data value and the data value to be input is specified. Then, the specified data value is stored in an area of the management area (that is, area not referred to in post-processing) storing the pointer for the key of the data value.
With this, it is possible to sort and store the data value for each key without using an additional area other than the data storage area and overwriting the data value.
By using
As illustrated in
As illustrated in
As illustrated in
As illustrated in
As illustrated in
By processes so far, as illustrated in
In the following description, a process performed by the information processing device 1 is described in more detail. As a premise, it is assumed that information of distribution (hereinafter, it is assumed that C[k] (k=1, 2, . . . , σ). σ is the number of keys and natural number of 2 or more) for each key is stored in the input data storage unit 111. In addition, in the following description, it is assumed that the pointer to the data value is stored in X[i] of the data storage area.
First, the head specifying unit 101 performs a head specifying process (
The head specifying unit 101 sets 1 as a variable h representing the head (
The head specifying unit 101 sets k, which is an identification number of key, at 1 (step S13). As described above, the order of the plurality of keys is predetermined in the embodiment. For example, in a case where the position of the key “a” in the order is before the position of the key “b” in the order, the identification number of the key “a” is smaller than the identification number of the key “b”.
The head specifying unit 101 sets a value of C[k] to a variable num representing the distribution (step S15).
The head specifying unit 101 sets a value of h to C[k] (step S17). By this process, since C[k] becomes the pointer indicating the head position for the key of which the identification number is “k”, the head specifying unit 101 stores the C[k] in the management area.
The head specifying unit 101 sets (h+num−1) to h (step S19). By this process, the h becomes the pointer indicating the head position for the next key.
The head specifying unit 101 increments the k by 1 (step S21).
The head specifying unit 101 determines whether k>σ is satisfied (step S23)
In a case where k>σ is not satisfied (step S23: No route), since the head specifying unit 101 processes the next k, the process returns to step S15. Meanwhile, in a case where k>σ is satisfied (step S23: Yes route), the process returns to the caller.
If the above process is performed, the pointer is set in the management area among the data storage areas, as illustrated in
Returning to the description of
The storage processing unit 103 reads one pointer p to the data value from the input data storage unit 111. Then, the storage processing unit 103 sets C[key (p)] to a variable i that is the identification number indicating the storage position (step S33). The key (p) is the identification number of key of the data value represented by the pointer p.
The storage processing unit 103 determines whether X[i] is empty (that is, value is not set to X[i]) (step S35).
In a case where X[i] is empty (step S35: Yes route), the pointer to another data value is not stored in an area of X[i]. Therefore, the storage processing unit 103 sets p in X[i] (step S37).
The storage processing unit 103 sets C[key (p)]+1 in C[key (p)] (step S39). That is, the storage processing unit 103 updates the pointer for key (p) to indicate an adjacent area.
Meanwhile, in a case where X[i] is not empty (step S35: Yes route), the pointer to another data value is stored in an area of X[i]. Therefore, the storage processing unit 103 sets X[i] in a variable s indicating the pointer to another data value (step S41).
The storage processing unit 103 determines whether i>M is satisfied (step S43). The M is the sum (for example, 6 in a case of examples of
In a case where i>M is satisfied (step S43: Yes route), the pointer p is the last read pointer. Therefore, the storage processing unit 103 sets the pointer p in C[key (p)] (step S45).
Meanwhile, in a case where i>M is not satisfied (step S43: No route), the pointer p is not the last read pointer. Therefore, the storage processing unit 103 determines whether key (s)>key (p) is satisfied (step S47). That is, the storage processing unit 103 determines whether the position of key (s) in the order is after the position of key (p) in the order.
In a case where key (s)>key (p) is satisfied (step S47: Yes route), the position of key (s) in the order is after the position of key (p) in the order. Therefore, the process proceeds to step S45.
In a case where key (s)>key (p) is not satisfied (step S47: No route), the position of key (s) in the order is before the position of key (p) in the order. Therefore, the storage processing unit 103 sets p in X[i] (step S49).
The storage processing unit 103 sets the pointer s in C[key (s)] (step S51).
The storage processing unit 103 sets C[key (p)]+1 in C[key (p)] (step S53). That is, the storage processing unit 103 updates the pointer for key (p) to indicate an adjacent area. Then, the process returns to the caller.
If the above process is performed, the pointer as illustrated in
Returning to the description of
If the above process is performed, it is possible to perform a process for sorting the plurality of types of data based on the types thereof and storing the sorted result while suppressing the use amount of the data storage area. With this, it is possible to suppress deterioration of other processes due to performance of a sorting process or the like.
As described above, the embodiment is described. However, the embodiments discussed herein is not limited thereto. For example, a functional block configuration of the information processing device 1 described above may not match an actual program module configuration in some cases.
In addition, the above-described data configuration is an example, and it does not have to be configured as described above. Furthermore, also in a process flow, if the processing result does not change, it is also possible to change the order of the processing. Furthermore, it may be made to perform in parallel.
In the example described above, the pointer p to each data value is read from the input data, but the storage processing unit 103 may sequentially accept the input of the pointer p from the user or the like, or the information processing device 1 may sequentially receive the pointer p from another device.
The information processing device 1 is described below is a computer device. As illustrated in
The above-described embodiment is summarized as follows.
A storage method according to a first aspect of the embodiment includes a process of (A) storing information of a storage position in the management area within the data storage area for each of the plurality of types in accordance with a number that each piece of the plurality of types of data has for each type and the order of the plurality of types in target data including the plurality of types of data, (B) specifying the storage position of the input data from the management area based on the type of the input data according to input of data included in the target data, (C) storing the input data in the specified storage position in a case where other data is not stored in the specified storage position, and (D) storing the input data in a position in which the information of the storage position corresponding to the type of the input data in the management area is stored or in the specified storage position based on comparison of the position of the type of other data in the order and the position of the type of the input data in the order in a case where other data is stored in the specified storage position.
It is possible to perform a process sorted and stored based on the type of the plurality of types of data that are sequentially input while suppressing the use amount of the data storage area.
In addition, in a process of storing the input data when other data is stored in the specified storage position, (d1) the input data may be stored in the specified storage position in a case where other data is stored in the specified storage position and the position of the type of other data in the order is before the position of the type of the input data in the order, and (d2) the input data may be stored in a position of the management area in which the information of the storage position corresponding to the type of the input data is stored when other data is stored in the specified storage position and the position of the type of other data in the order is after the position of the type of the input data in the order.
In addition, the storage method may further include (E) a process of updating the information of the storage position corresponding to the type of the input data stored in the management area.
In this manner, it is possible to store data to be input in the next time in an appropriate position.
In addition, this storage method may further include (F) a process of storing other data in a position of the management area in which the information of the storage position corresponding to the type of other data is stored in a case where other data is stored in the specified storage position and the position of the type of other data in the order is before the position of the type of the input data in the order.
In this manner, no other data originally stored in the specified storage position is deleted by rewriting.
In addition, this storage method may further include (G) a process for rearranging data stored in the management area and data stored in an area other than the management area among the data storage areas in a case where input of data included in the target data is completed, in an input order for each type.
Even in a case where a state after storing is not an appropriate state, it is possible to correct an appropriate state.
In addition, the number of the storage positions included in the data storage area may be equal to the sum of the number of pieces of data for each of the plurality of types.
In this manner, it is possible to minimize an area to be used.
A storage apparatus according to a second aspect of the embodiment includes (H) a first processing unit (for example, head specifying unit 101) that stores the information of a storage position in the management area within the data storage area for each of the plurality of types in accordance with a number that each piece of the plurality of types of data has for each type and the order of the plurality of types in the target data including the plurality of types of data, and (I) a second processing unit (for example, storage processing unit 103) that specifies the storage position of the input data from the management area based on the type of the input data according to the input of the data included in the target data, stores the input data in the specified storage position in a case where data is not stored in the specified storage position, and stores the input data in a position in which the information of the storage position corresponding to the type of the input data is stored in the management area or in the specified storage position based on comparison between the position of the type of other data in the order and the position of the type of the input data in the order in a case where other data is stored in the specified storage position.
A program for causing a processor to perform the processes according to the above method may be created and the program may be stored in a computer-readable storage medium or a storage device such as a flexible disk, a CD-ROM, a magneto-optical disk, a semiconductor memory, and a hard disk. The intermediate processing result is temporarily stored in a storage device such as a main memory.
All examples and conditional language recited herein are intended for pedagogical purposes to aid the reader in understanding the invention and the concepts contributed by the inventor to furthering the art, and are to be construed as being without limitation to such specifically recited examples and conditions, nor does the organization of such examples in the specification relate to a showing of the superiority and inferiority of the invention. Although the embodiments of the present invention have been described in detail, it should be understood that the various changes, substitutions, and alterations could be made hereto without departing from the spirit and scope of the invention.
Number | Date | Country | Kind |
---|---|---|---|
2017-025401 | Feb 2017 | JP | national |