CN114579835A - Data storage method, data query method and related equipment - Google Patents

Data storage method, data query method and related equipment Download PDF

Info

Publication number
CN114579835A
CN114579835A CN202210495911.0A CN202210495911A CN114579835A CN 114579835 A CN114579835 A CN 114579835A CN 202210495911 A CN202210495911 A CN 202210495911A CN 114579835 A CN114579835 A CN 114579835A
Authority
CN
China
Prior art keywords
value
user account
byte
state
storage
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
CN202210495911.0A
Other languages
Chinese (zh)
Other versions
CN114579835B (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.)
Shenzhen Flash Scissor Intelligent Technology Co ltd
Original Assignee
Shenzhen Big Head Brothers Technology 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 Shenzhen Big Head Brothers Technology Co Ltd filed Critical Shenzhen Big Head Brothers Technology Co Ltd
Priority to CN202210495911.0A priority Critical patent/CN114579835B/en
Publication of CN114579835A publication Critical patent/CN114579835A/en
Application granted granted Critical
Publication of CN114579835B publication Critical patent/CN114579835B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/951Indexing; Web crawling techniques
    • 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/95Retrieval from the web
    • G06F16/953Querying, e.g. by the use of web search engines
    • G06F16/9535Search customisation based on user profiles and personalisation

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)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a data storage and query method and related equipment, wherein the method comprises the steps of obtaining an active state modification instruction, wherein the active state modification instruction comprises a user account and an active state corresponding to the user account; determining corresponding storage bytes and byte digits according to the user account; generating a first ideal state value corresponding to the user account according to the byte number and the active state; taking the value of the storage byte as a real state value, and performing bit AND operation on the real state value and the first ideal state value to obtain a first bit AND value; and updating the real state value according to the first bit and the numerical value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction. Compared with the prior storage mode, the invention can store more information on the basis of the same storage volume, thereby saving the storage space.

Description

Data storage method, data query method and related equipment
Technical Field
The invention relates to the technical field of data processing, in particular to a data storage method, a data query method and related equipment.
Background
With the development of the internet, internet users are more and more, and with the use of users, information related to the users is more and more, such as purchase records of the users, login records of the users, and the like. Thus, as time goes on and users grow, more and more user information is available. The most common information among the user-related information is the record of the login state of the user.
The user is in a login state, the record of the user login state in subsequent access is generally stored by adopting bytes, and the hash value is used for searching. For example, if 1000 ten thousand users exist in a certain website, 1000 ten thousand/1024/1024 ≈ 9.5Mb space is needed for storage at the same time. Therefore, the storage space is large, and the storage space is large, so that the problems of unchanged storage and the like are caused.
Disclosure of Invention
The invention aims to solve the technical problems that storage difficulty of a user login state is high, and data storage and query methods and related equipment are provided aiming at the defects of the prior art.
In order to solve the technical problems, the technical scheme adopted by the invention is as follows:
a method of data storage, the method comprising:
acquiring an active state modification instruction, wherein the active state modification instruction comprises a user account and an active state corresponding to the user account;
determining corresponding storage bytes and byte digits according to the user account;
generating a first ideal state value corresponding to the user account according to the byte number and the active state;
taking the value of the storage byte as a real state value, and carrying out bit AND operation on the real state value and the first ideal state value to obtain a first bit and value;
and updating the real state value according to the first bit and the numerical value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction.
Optionally, the user account is a number; the determining the corresponding storage byte and the byte bit number according to the user account number comprises:
dividing the user account number by a preset storage digit number to obtain an integer part and a remainder part corresponding to the user account number, wherein the user account number is a dividend, and the storage digit number is a divisor;
the integer portion is taken as a storage byte and the remainder portion is taken as a byte bit number.
Optionally, the active state comprises active and inactive; the generating a first ideal state value corresponding to the user account according to the byte number and the active state comprises:
when the active state is active, performing left shift or right shift operation by taking the byte number as a moving numerical value to obtain a user state numerical value corresponding to the user account;
determining that the first ideal state value is zero when the active state is inactive.
Optionally, the updating the real state value according to the first bit and value and the first ideal state value, and obtaining a state update value corresponding to the active state modification instruction includes:
when the first bit sum value is greater than the first ideal state value, taking the real state value as a subtree and the first ideal state value as a subtree, and performing subtraction operation on the real state value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction;
and when the first bit sum value is smaller than the first ideal state value, calculating the sum of the real state value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction.
A method of data query, the method comprising:
acquiring a user account to be inquired;
determining storage bytes and byte bit numbers corresponding to the user account according to preset storage bit numbers;
calculating a second ideal state value corresponding to the user account according to the storage byte and a preset ideal active value;
taking the value of the storage byte as a real state value, and carrying out bit AND operation on the real state value and the second ideal state value to obtain a second bit and value;
and determining the active state corresponding to the user account according to the second digit and value and the second ideal state value.
Optionally, the user account is a number; the determining the storage bytes and the byte bit number corresponding to the user account according to the preset storage bit number comprises:
dividing the user account number by the storage digit number to obtain an integer part and a remainder part corresponding to the user account number, wherein the user account number is a dividend, and the storage digit number is a divisor;
the integer portion is taken as a stored byte and the remainder portion is taken as a byte bit number.
Optionally, the calculating, according to the storage byte, a second ideal state value corresponding to the user account includes:
and performing left shift or right shift operation by taking the byte number as a shift numerical value to obtain a second ideal state value corresponding to the user account.
Optionally, the determining, according to the second digit and value and the second ideal state value, an active state corresponding to the user account includes:
when the second digit and the value are equal to the second ideal state value, determining that the active state corresponding to the user account is the ideal active value;
and when the first bit and the numerical value are not equal to the second ideal state value, determining that the active state corresponding to the user account is a non-ideal active value.
A computer readable storage medium storing one or more programs, the one or more programs being executable by one or more processors to perform steps in a data query and/or data storage method as described in any above.
A terminal device, comprising: a processor, a memory, and a communication bus; the memory has stored thereon a computer readable program executable by the processor;
the communication bus realizes connection communication between the processor and the memory;
the processor, when executing the computer readable program, implements the steps in the data query and/or data storage method as described in any of the above.
Has the advantages that: the present invention provides a data storage method, wherein currently, the storage is in byte units, and the present invention uses bits in the bytes as storage units, and each bit represents an active state corresponding to a user. When the active state of the user needs to be stored, on one hand, the byte to be stored and the number of bits in the byte are determined according to the account number. On the other hand, an ideal first ideal state value is generated from the number of bits. Comparing the ideal first ideal state value with the storage byte, and if the ideal first ideal state value is the same as the storage byte, indicating that the currently stored active state does not need to be modified; if the two ideal state values are different, updating the currently stored bytes according to the first ideal state value and the comparison result so as to realize data storage. On the basis of the storage, the scheme also provides a query method, after the bytes and the digits are obtained, a numerical value for comparison is generated, and the second ideal state value represents that the user is active or inactive. Then, it is calculated whether the second ideal state value and the real state value are equal to each other. If the second ideal state value represents activity and the second ideal state value is equal to the real state value, indicating that the state corresponding to the user account is active; if the second ideal state value represents inactivity and the comparison value is equal to the real state value, it indicates that the state corresponding to the user account is inactive, and so on, the state corresponding to the user account can be obtained.
Drawings
Fig. 1 is a flowchart of a data storage method provided by the present invention.
FIG. 2 is a flowchart illustrating a data storage method according to the present invention.
FIG. 3 is a flowchart illustrating a data query method according to the present invention.
Fig. 4 is a schematic structural diagram of a terminal device provided in the present invention.
Detailed Description
The invention provides a data storage and query method and related equipment, and in order to make the purpose, technical scheme and effect of the invention clearer and clearer, the invention is further described in detail below by referring to the attached drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and do not limit the invention.
As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and/or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may also be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. As used herein, the term "and/or" includes all or any element and all combinations of one or more of the associated listed items.
It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. It will be further understood that terms, such as those defined in commonly used dictionaries, should be interpreted as having a meaning that is consistent with their meaning in the context of the prior art and will not be interpreted in an idealized or overly formal sense unless expressly so defined herein.
As shown in fig. 1, the present embodiment provides a data storage method, which is described by taking a common server as an execution subject for convenience of description, where the server may be replaced with a tablet, a computer, or other devices with data processing functions, and the data storage method includes the following steps:
s10, obtaining an active state modification instruction, wherein the active state modification instruction comprises a user account and an active state corresponding to the user account.
Specifically, each user has a corresponding user account, and if receiving an active state modification instruction, which indicates that the active state of a certain user is stored, the user account of the user and the active state that needs to be stored need to be acquired. Therefore, the active state modification instruction includes the user account and the active state corresponding to the user account.
The active state has only two values, one is active and one is inactive. In this embodiment, the user account is a computable numerical value or a text, so as to facilitate subsequent storage and calculation. In this example, the user account "13" and the active state are described as an example of "active".
And S20, determining the corresponding storage byte and the byte digit number according to the user account.
Specifically, the number of storage bits refers to the number of bits contained in one byte in the system. The bit number of one byte in a general system is 8 bits, and in different systems, the bit number can be adjusted according to the actual storage bit number. The byte number is the number of bits of the credit activity state value corresponding to the user account stored on the basis of the storage number of bits.
For the convenience of searching, a key-value pair (key-value) is preset in this example, where the key is a user account, and the value refers to a stored byte. The number of memory bits used in this example is usually 8 bits, and thus the type of value set is uint 8. The key-value pair may be set using the following code.
//
type Bitmap struct {
Data map [ uint32] byte// byte = uint8 storage occupies one byte
}
In one implementation, different user accounts are pre-mapped to storage locations of active states thereof, and the mapping relationship may be stored in a location table. For example, user account "13" corresponds to the first byte, 2 nd position, and user account "12" corresponds to the second byte, 3 rd position. After the user account is obtained, the storage bytes and the byte digit number corresponding to the user account can be determined through the position table.
The method needs to preset a storage position, has more steps and is easy to tamper. Therefore, in another implementation mode, the determination according to the user account and the storage bit number can be adopted. In this example, the user account is a numerical value, and for a user who registers and logs in with a character, a code that can be calculated is set in the server as a user account for subsequent storage. For example, the user name is "hat" and the user account number is "13". The specific process is as follows:
a10, dividing the user account number and the storage digit number to obtain an integer part and a remainder part corresponding to the user account number, wherein the user account number is a dividend, and the storage digit number is a divisor.
Specifically, the user account is used as a dividend, the number of digits is stored as a divisor, and the user account and the number of digits are divided to obtain an integer part and a remainder part.
Taking the user account number "3" as an example, after dividing by the number of stored digits, the integer part is 0 and the remainder part is 3.
Taking the user account number "8" as an example, after dividing by the number of stored digits, the integer part is 1, and the remainder part is 0.
Taking the user account number "13" as an example, after dividing by the number of stored digits, the integer part is 1 and the remainder part is 5.
A20, determining the storage byte and the byte digit number corresponding to the user account according to the integer part and the remainder part.
Specifically, in one determination mode, when the remainder is a natural number, the sum of the integer part and 1 is used as the storage byte corresponding to the user account, and the remainder part is used as the storage byte corresponding to the user account. The storage bytes corresponding to "3" and "13" in the previous example are 1 and 2, respectively, and the byte bit number is "3" and "5".
And when the remainder is zero, taking the integer part as a storage byte corresponding to the user account, wherein the byte digit number corresponding to the user account is equal to the storage digit number. As in the previous example "8", the corresponding storage byte is 1 and the number of storage bits is 8.
In the second determination, it is preset that zero is used as the starting point of the count, such as 0 th byte, the first byte … …, and the 0 bit indicates the last bit of the previous byte. Thus, according to this setting, the number of bytes stored and the number of bytes can be determined directly after the integer part and the remainder part are obtained.
In addition, in the third determination method, as shown in fig. 2, zero is used as the starting point of the count, for example, the 0 th byte and the first byte … … are sorted, and the byte is also used as the starting point of 0, the integer part is directly used as the storage byte, the remainder is used as the storage bit number, and the 0 th byte bit number is equivalent to the first bit in the storage byte.
The code may be expressed as:
// GetBIT obtaining the value stored by the bit
func (b Bitmap) GetBit(key uint32) bool {
// take the corresponding value
index := key / 8
n := key % 8
target := b.Data[index]
Wherein, key is the user account number, index is the storage byte, and n is the byte number. target refers to the value corresponding to the byte used.
And S30, generating a first ideal state value corresponding to the user account according to the byte number and the active state.
Specifically, information is generally performed in units of bytes, and the active state to be stored and the currently stored active state can be directly compared and stored. However, since the information is stored in units of bits, the server cannot directly obtain the specific information of all bits in one byte, and therefore, in order to solve this problem, this embodiment adopts a method of comparing an ideal value with an actual value.
First, an ideal value, i.e. a first ideal state value, is generated according to the byte number and the active state. Since the bit can only store "0" or "1", the active state is bound to "0" and "1" in advance. For example, the value corresponding to "active" is "1", and the state corresponding to "inactive" is "0".
And when the active state is active, performing left shift or right shift operation by taking the byte number as a moving numerical value to obtain a user state numerical value corresponding to the user account. In the previous example, the number of bytes is 5, and if the left shift operation, i.e., "1 < < 5", is used, the obtained value is represented by "00010000" in bits, and therefore the ideal user status value corresponding to the account "13" is "00010000". When the active state is inactive, the ideal user state value is zero, expressed in 8 bits as "00000000". In practice, the left shift operation may be adopted, and each binary bit in the right shift operation is all shifted to the right by a plurality of bits, and for unsigned numbers, high-order bits are supplemented with 0, signed numbers, the processing methods of each compiler are different, and some complementary sign bits (arithmetic right shift) and some complementary 0 (logical right shift) are similar to the left shift operation.
In addition, if the value corresponding to "active" is set to be "0" and the value corresponding to "inactive" is set to be "1", when the active state is active, the first ideal state value is zero; and when the active state is inactive, performing left shift or right shift operation by taking the byte number as a moving numerical value to obtain a user state numerical value corresponding to the user account.
This process code may be the following:
n2Pow := uint8(1 << n)
where n2Pow is the first ideal state value.
And S40, taking the value of the storage byte as a real state value, and performing bit AND operation on the real state value and the first ideal state value to obtain a first bit AND value.
Specifically, the value of the storage byte is used as a true state value, and the storage byte stores the true storage value relative to the previously obtained ideal value, i.e., the first ideal state value. Bit-and-arithmetic may enable bit-to-bit comparison calculations, and thus comparison of ideal and real values.
In the bit AND operation, when the AND operation (&) is that two bits are both 1, the result is 1; an OR operation (|) has two bits of 0, and the result is 0. The first bit and value, which includes "0" and "1", represents the comparison of the ideal value to the true value.
Taking the ideal state value of "00010000" as an example, the real state value is "11010000", and the and operation in the bit and operation is adopted, and since the values of the fifth bit from the back to the front are all 1, the first bit and value after the operation is "00010000".
If "active" is used for "0" and "inactive" is used for "1", the first bit and value can be calculated by using an or operation in the operation.
And S50, updating the real state value according to the first bit and value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction.
Specifically, the first bit and value are compared to determine if they are the same as the first ideal state value. If the two values are the same, it indicates that in the real state value, the value of the byte number corresponding to the user account represents the active state of the user account at the moment, so that the value does not need to be updated.
When the first digit and the numerical value are different from the first ideal state value, it indicates that in the real state value, the numerical value of the byte digit corresponding to the user account does not represent the active state of the user account at the moment, and therefore needs to be modified.
In this example, the "active" corresponds to "1", and as shown in fig. 2, the true state value before storage is "11000000", and the first ideal state value is "00010000". The value of the byte number corresponding to the user account is "0", and the previous active state is "inactive", so that modification is required.
And when the first bit sum value is smaller than the first ideal state value, calculating the sum of the real state value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction. In the above example, the sum of "11000000" and "00010000" is to obtain "11010000", the value of the byte number corresponding to the user account is "1", and corresponds to the active state "active" that needs to be saved. Therefore, the real state value is updated, and the state update value corresponding to the active state modification instruction is obtained.
On the contrary, when the first bit sum value is greater than the first ideal state value, the real state value is taken as a decrement, the first ideal state value is taken as a decrement, and the real state value and the first ideal state value are subtracted to obtain a state update value corresponding to the active state modification instruction. Namely, the byte number corresponding to the user account is changed from '1' to '0'.
The code for this process may be expressed as:
if (target & n2Pow) == n2Pow {
return true
}
return false
in this embodiment, data storage is in bits, and therefore more data can be stored on the same storage capacity than that previously stored in bytes. Taking a byte of 8 bits as an example, in the case of the same data, the present solution only occupies 1/8 space in the existing solution. And the map key value pair mode is stored, so need not set up too big keyword (key) and need continuous occupation space like the array, this scheme can occupy discontinuous space in a flexible way, and the byte of storage can be discontinuous promptly, can distribute in different regions, can the limit utilize storage space.
Based on the above data storage method, the present invention further provides a data query method, for convenience of description, a common server is used as an execution subject for description, where the server may be replaced with a tablet, a computer, and other devices having a data processing function, and the data storage method includes the following steps:
and B10, acquiring the user account to be queried.
Specifically, as for the active state corresponding to the user account to be stored, the user account and the active state corresponding to the user account are needed, and only the user account is needed to query the user account.
B20, determining the storage bytes and byte digit numbers corresponding to the user account according to the preset storage digit numbers.
Specifically, in the present embodiment, the storage bit number refers to the number of bits included in one byte in the system. The bit number of one byte in a general system is 8 bits, and in different systems, the bit number can be adjusted according to the actual storage bit number.
For the convenience of searching, a key-value pair (key-value) is preset in this example, where the key is a user account, and the value refers to a stored byte. The number of memory bits used in this example is usually 8 bits, and thus the type of value set is uint 8. The key-value pair may be set using the following code.
//
type Bitmap struct {
Data map [ uint32] byte// byte = uint8 storage occupies one byte
}
In one implementation, different user accounts are pre-mapped to storage locations of active states thereof, and the mapping relationship may be stored in a location table. For example, user account "13" corresponds to the first byte, position 2, and user account "12" corresponds to the second byte, position 3. After the user account is obtained, the storage bytes and the byte digit number corresponding to the user account can be determined through the position table.
The method needs to preset a storage position, has more steps and is easy to tamper. Therefore, in another implementation mode, the determination according to the user account and the storage bit number can be adopted. In this example, the user account is a numerical value, and for a user who registers and logs in with a character, a code that can be calculated is set in the server as a user account for subsequent storage. For example, the user name is "hat" and the user account number is "13". The specific process of determining the number of storage bits and the number of byte bits comprises the following steps:
and C10, dividing the user account number and the storage digit number to obtain an integer part and a remainder part corresponding to the user account number, wherein the user account number is a dividend, and the storage digit number is a divisor.
Specifically, the user account is used as a dividend, the number of digits is stored as a divisor, and the user account and the number of digits are divided to obtain an integer part and a remainder part.
Taking the user account number "3" as an example, after dividing by the number of stored digits, the integer part is 0 and the remainder part is 3.
Taking the user account number "8" as an example, after dividing by the number of stored digits, the integer part is 1, and the remainder part is 0.
Taking the user account number "13" as an example, after dividing by the number of stored digits, the integer part is 1 and the remainder part is 5.
And C20, determining the storage byte and the byte digit number corresponding to the user account according to the integer part and the remainder part.
Specifically, in one determination mode, when the remainder is a natural number, the sum of the integer part and 1 is used as the storage byte corresponding to the user account, and the remainder part is used as the storage byte corresponding to the user account. The storage bytes corresponding to "3" and "13" in the previous example are 1 and 2, respectively, and the byte bit number is "3" and "5".
And when the remainder is zero, taking the integer part as a storage byte corresponding to the user account, wherein the byte digit number corresponding to the user account is equal to the storage digit number. As in the previous example "8", the corresponding storage byte is 1 and the number of storage bits is 8.
In the second determination, it is preset that zero is used as the starting point of the count, such as 0 th byte, the first byte … …, and the 0 bit indicates the last bit of the previous byte. Thus, according to this setting, the number of bytes stored and the number of bytes can be determined directly after the integer part and the remainder part are obtained.
In addition, in the third determination method, as shown in fig. 2, zero is used as the starting point of the count, for example, the 0 th byte and the first byte … … are sorted, and the byte is also used as the starting point of 0, the integer part is directly used as the storage byte, the remainder is used as the storage bit number, and the 0 th byte bit number is equivalent to the first bit in the storage byte.
The code may be expressed as:
// GetBIT obtaining the value stored by the bit
func (b Bitmap) GetBit(key uint32) bool {
// take the corresponding value
index := key / 8
n := key % 8
target := b.Data[index]
Wherein, key is the user account number, index is the storage byte, and n is the byte number. target refers to the value corresponding to the byte to be stored.
And B30, calculating a second ideal state value corresponding to the user account according to the storage byte and a preset ideal active value.
Specifically, information is generally performed in units of bytes, and the active state to be stored and the currently stored active state can be directly compared and queried. However, the server cannot directly obtain the specific information of all bits in one byte by taking a bit as a unit, so this embodiment adopts a method of comparing an ideal value with an actual value to solve this problem.
The bit can only store '0' or '1', and the active state is bound with '0' and '1' in advance. For example, the value corresponding to "active" is "1", and the state corresponding to "inactive" is "0". Meanwhile, an ideal activity value is preset, that is, an activity state corresponding to the user account is expected, and in this embodiment, the set ideal activity value is "1", that is, "active".
And generating an ideal value, namely a second ideal state value according to the byte number and the preset ideal activity value. And performing left shift or right shift operation by taking the byte number as a shift numerical value to obtain a user state numerical value corresponding to the user account. In the previous example, the number of bytes is 5, and if the left shift operation, i.e., "1 < < 5", is used, the obtained value is represented by "00010000" in bits, and therefore the ideal user status value corresponding to the account "13" is "00010000". In practice, the left shift operation may be adopted, and each binary bit in the right shift operation is all shifted to the right by a plurality of bits, and for unsigned numbers, high-order bits are supplemented with 0, signed numbers, the processing methods of each compiler are different, and some complementary sign bits (arithmetic right shift) and some complementary 0 (logical right shift) are similar to the left shift operation.
This process code may be the following:
n2Pow := uint8(1 << n)
where n2Pow is the second ideal state value.
And B40, taking the value of the storage byte as a real state value, and carrying out bit AND operation on the real state value and the second ideal state value to obtain a second bit AND value.
Specifically, the value of the storage byte is used as a true state value, and the storage byte stores the true storage value relative to the previously obtained ideal value of the second ideal state value. Bit-and-operations may enable comparison computations between bits, and thus comparison of ideal and real values.
In the bit AND operation, when the AND operation (&) is that two bits are both 1, the result is 1; an OR operation (|) has two bits of 0, and the result is 0. The first bit and value includes "0" and "1" and represents the comparison of the ideal value and the actual value.
Taking the ideal state value of "00010000" as an example, the real state value is "11010000", and the and operation in the bit and operation is adopted, and since the values of the fifth bit from the back to the front are all 1, the first bit and value after the operation is "00010000".
And B50, determining the active state corresponding to the user account according to the second digit and value and the second ideal state value.
Specifically, the second bit and value are compared to the ideal state value for the same. If the two values are the same, it indicates that the value of the byte number corresponding to the user account in the real state value is the preset ideal active state. If the actual state value is different from the preset ideal active state, the value of the byte number corresponding to the user account is not in the real state value.
Then, because there are only two active states, if the set ideal active state is "active" and the second bit and value are equal to the second ideal state value, it is determined that the active state corresponding to the user account is the preset ideal active state, i.e., "active"; if the set ideal active state is "active" and the second digit and value are not equal to the second ideal state value, determining that the active state corresponding to the user account is a non-ideal active state, that is, the active state corresponding to the user account is "non-active".
The invention provides a data query method based on the data storage scheme, which can quickly realize the active state data stored by each bit, and adopts a key-value mode to directly query, thereby improving the query rate.
Based on the above data storage and query method, the present invention further provides a terminal device, as shown in fig. 4, which includes at least one processor (processor) 20; a display screen 21; and a memory (memory) 22, and may further include a communication Interface (Communications Interface) 23 and a bus 24. The processor 20, the display 21, the memory 22 and the communication interface 23 can communicate with each other through the bus 24. The display screen 21 is configured to display a user guidance interface preset in the initial setting mode. The communication interface 23 may transmit information. The processor 20 may call logical commands in the memory 22 to perform the methods in the above embodiments.
In addition, the logic commands in the memory 22 can be implemented in the form of software functional units and stored in a computer readable storage medium when sold or used as a stand-alone product.
The memory 22, which is a computer-readable storage medium, may be configured to store a software program, a computer-executable program, such as program commands or modules corresponding to the methods in the embodiments of the present disclosure. The processor 20 executes functional applications and data processing by executing software programs, commands or modules stored in the memory 22, i.e. implements the method in the above-described embodiments.
In implementing the data storage method, the method includes:
acquiring an active state modification instruction, wherein the active state modification instruction comprises a user account and an active state corresponding to the user account;
determining corresponding storage bytes and byte digits according to the user account;
generating a first ideal state value corresponding to the user account according to the byte number and the active state;
taking the value of the storage byte as a real state value, and carrying out bit AND operation on the real state value and the first ideal state value to obtain a first bit and value;
and updating the real state value according to the first bit and the numerical value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction.
Wherein the user account is a number; the determining the corresponding storage byte and the byte bit number according to the user account number comprises:
dividing the user account number by the storage digit number to obtain an integer part and a remainder part corresponding to the user account number, wherein the user account number is a dividend, and the storage digit number is a divisor;
the integer portion is taken as a stored byte and the remainder portion is taken as a byte bit number.
Wherein the active state comprises active and inactive; the generating a first ideal state value corresponding to the user account according to the byte number and the active state comprises:
when the active state is active, performing left shift or right shift operation by taking the byte number as a moving numerical value to obtain a user state numerical value corresponding to the user account;
determining that the first ideal state value is zero when the active state is inactive.
Wherein the updating the real state value according to the first bit and value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction includes:
when the first bit sum value is greater than the first ideal state value, taking the real state value as a subtree and the first ideal state value as a subtree, and performing subtraction operation on the real state value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction;
and when the first bit sum value is smaller than the first ideal state value, calculating the sum of the real state value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction.
In implementing the data query method, the method comprises:
acquiring a user account to be inquired;
determining storage bytes and byte bit numbers corresponding to the user account according to preset storage bit numbers;
calculating a second ideal state value corresponding to the user account according to the storage byte and a preset ideal active value;
taking the value of the storage byte as a real state value, and carrying out bit AND operation on the real state value and the second ideal state value to obtain a second bit and value;
and determining the active state corresponding to the user account according to the second digit and value and the second ideal state value.
Wherein the user account is a number; the determining the storage bytes and the byte bit number corresponding to the user account number according to the preset storage bit number comprises:
dividing the user account number by the storage digit number to obtain an integer part and a remainder part corresponding to the user account number, wherein the user account number is a dividend, and the storage digit number is a divisor;
the integer portion is taken as a stored byte and the remainder portion is taken as a byte bit number.
Wherein the calculating a second ideal state value corresponding to the user account according to the storage byte comprises:
and performing left shift or right shift operation by taking the byte number as a shift numerical value to obtain a second ideal state value corresponding to the user account.
Wherein the determining the active state corresponding to the user account according to the second digit and value and the second ideal state value comprises:
when the second digit and the value are equal to the second ideal state value, determining that the active state corresponding to the user account is the ideal active value;
and when the first bit and the numerical value are not equal to the second ideal state value, determining that the active state corresponding to the user account is a non-ideal active value.
The memory 22 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the terminal device, and the like. Further, the memory 22 may include a high speed random access memory and may also include a non-volatile memory. For example, a variety of media that can store program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk, may also be used as the transient computer readable storage medium.
In addition, the specific processes loaded and executed by the computer readable storage medium and the plurality of command processors in the terminal device are described in detail in the method, and are not stated herein.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. A method of data storage, the method comprising:
acquiring an active state modification instruction, wherein the active state modification instruction comprises a user account and an active state corresponding to the user account;
determining corresponding storage bytes and byte digits according to the user account;
generating a first ideal state value corresponding to the user account according to the byte number and the active state;
taking the value of the storage byte as a real state value, and carrying out bit AND operation on the real state value and the first ideal state value to obtain a first bit and value;
and updating the real state value according to the first bit and the numerical value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction.
2. The data storage method of claim 1, wherein the user account is a number; the determining the corresponding storage byte and the byte bit number according to the user account number comprises:
dividing the user account number by a preset storage digit number to obtain an integer part and a remainder part corresponding to the user account number, wherein the user account number is a dividend, and the storage digit number is a divisor;
the integer portion is taken as a stored byte and the remainder portion is taken as a byte bit number.
3. The data storage method of claim 2, wherein the active state comprises active and inactive; the generating a first ideal state value corresponding to the user account according to the byte number and the active state comprises:
when the active state is active, performing left shift or right shift operation by taking the byte number as a moving numerical value to obtain a user state numerical value corresponding to the user account;
determining that the first ideal state value is zero when the active state is inactive.
4. The data storage method of claim 2, wherein the updating the real state value according to the first bit and value and the first ideal state value to obtain the state update value corresponding to the active state modification instruction comprises:
when the first bit sum value is greater than the first ideal state value, taking the real state value as a subtree and the first ideal state value as a subtree, and performing subtraction operation on the real state value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction;
and when the first bit sum value is smaller than the first ideal state value, calculating the sum of the real state value and the first ideal state value to obtain a state update value corresponding to the active state modification instruction.
5. A data query method, which is applied to the data storage method according to any one of claims 1 to 4, characterized by comprising the following steps:
acquiring a user account to be inquired;
determining storage bytes and byte bit numbers corresponding to the user account according to preset storage bit numbers;
calculating a second ideal state value corresponding to the user account according to the storage byte and a preset ideal active value;
taking the value of the storage byte as a real state value, and carrying out bit AND operation on the real state value and the second ideal state value to obtain a second bit and value;
and determining the active state corresponding to the user account according to the second digit and value and the second ideal state value.
6. The data query method of claim 5, wherein the user account is a number; the determining the storage bytes and the byte bit number corresponding to the user account number according to the preset storage bit number comprises:
dividing the user account number by the storage digit number to obtain an integer part and a remainder part corresponding to the user account number, wherein the user account number is a dividend, and the storage digit number is a divisor;
the integer portion is taken as a stored byte and the remainder portion is taken as a byte bit number.
7. The data query method of claim 5, wherein the calculating a second ideal state value corresponding to the user account according to the storage byte comprises:
and performing left shift or right shift operation by taking the byte number as a shift numerical value to obtain a second ideal state value corresponding to the user account.
8. The method of claim 5, wherein determining the active state corresponding to the user account according to the second digit and value and the second ideal state value comprises:
when the second digit and the value are equal to the second ideal state value, determining that the active state corresponding to the user account is the ideal active value;
and when the first bit and the numerical value are not equal to the second ideal state value, determining that the active state corresponding to the user account is a non-ideal active value.
9. A computer readable storage medium storing one or more programs, the one or more programs being executable by one or more processors to perform the steps of the data storage method of any one of claims 1 to 4 and/or the data storage method of any one of claims 5 to 8.
10. A terminal device, comprising: a processor, a memory, and a communication bus; the memory has stored thereon a computer readable program executable by the processor;
the communication bus realizes connection communication between the processor and the memory;
the processor, when executing the computer readable program, implements the steps in the data storage method of any of claims 1 to 4 and/or the data storage method of any of claims 5 to 8.
CN202210495911.0A 2022-05-09 2022-05-09 Data storage method, data query method and related equipment Active CN114579835B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210495911.0A CN114579835B (en) 2022-05-09 2022-05-09 Data storage method, data query method and related equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210495911.0A CN114579835B (en) 2022-05-09 2022-05-09 Data storage method, data query method and related equipment

Publications (2)

Publication Number Publication Date
CN114579835A true CN114579835A (en) 2022-06-03
CN114579835B CN114579835B (en) 2022-08-05

Family

ID=81769299

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210495911.0A Active CN114579835B (en) 2022-05-09 2022-05-09 Data storage method, data query method and related equipment

Country Status (1)

Country Link
CN (1) CN114579835B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103995887A (en) * 2014-05-30 2014-08-20 上海达梦数据库有限公司 Bitmap index compressing method and bitmap index decompressing method
US20150278239A1 (en) * 2014-03-31 2015-10-01 Jive Software, Inc. Stream engine using compressed bitsets
CN108665121A (en) * 2017-03-27 2018-10-16 Tcl集团股份有限公司 A kind of method and system of computational intelligence terminal user retention ratio
CN110535944A (en) * 2019-08-29 2019-12-03 广州华多网络科技有限公司 The method and device of user's alive data processing
CN110535943A (en) * 2019-08-29 2019-12-03 广州华多网络科技有限公司 Data processing method, device, electronic equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150278239A1 (en) * 2014-03-31 2015-10-01 Jive Software, Inc. Stream engine using compressed bitsets
CN103995887A (en) * 2014-05-30 2014-08-20 上海达梦数据库有限公司 Bitmap index compressing method and bitmap index decompressing method
CN108665121A (en) * 2017-03-27 2018-10-16 Tcl集团股份有限公司 A kind of method and system of computational intelligence terminal user retention ratio
CN110535944A (en) * 2019-08-29 2019-12-03 广州华多网络科技有限公司 The method and device of user's alive data processing
CN110535943A (en) * 2019-08-29 2019-12-03 广州华多网络科技有限公司 Data processing method, device, electronic equipment and storage medium

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
CSDN: "缓存穿透利器之布隆过滤器", 《HTTP://WWW.CSDN.NET/TAGS/MTTAEG1SNZK4NJU4LWJSB2CO0O0O.HTML》 *
SUSHUIYUZHOU: "BitMap的原理和实现", 《HTTPS://BLOG.CSDN.NET/SUSHUIYUZHOU/ARTICLE/DETAILS/108449458》 *
程序员札记: "Redis Bitmap", 《HTTP://WWW.JIANSHU.COM/P/1D020C747088》 *

Also Published As

Publication number Publication date
CN114579835B (en) 2022-08-05

Similar Documents

Publication Publication Date Title
US11614936B2 (en) Systems and methods for performing 16-bit floating-point matrix dot product instructions
US11403071B2 (en) Systems and methods for performing instructions to transpose rectangular tiles
CN102232216B (en) Systems and methods for managing endian mode of a device
EP3252592A1 (en) Method and device for storing and reading data
CN111400308B (en) Processing method of cache data, electronic device and readable storage medium
CN110597865A (en) Method and device for processing user label, computing equipment and storage medium
CN110928935B (en) Data access command processing method, device and system
US11579883B2 (en) Systems and methods for performing horizontal tile operations
CN111897818A (en) Data storage method and device, electronic equipment and storage medium
CN112613053A (en) Data encryption and decryption method and device
US20240037084A1 (en) Method and apparatus for storing data
CN101324839A (en) Information processing apparatus
CN112487784B (en) Technical document management method, device, electronic equipment and readable storage medium
CN114579835B (en) Data storage method, data query method and related equipment
CN108108392B (en) Commodity data management method, commodity data management device, computer equipment and storage medium
CN109783321A (en) Monitoring data management method, device, terminal device
CN111090397B (en) Data deduplication method, system, equipment and computer readable storage medium
CN112347101A (en) Tag data storage method, computer device, and storage medium
CN112364041A (en) Data processing method and device, computer equipment and storage medium
US11256940B1 (en) Method, apparatus and system for gradient updating of image processing model
US20180101421A1 (en) Storage and application intercommunication using acpi
CN115543317A (en) Front-end page development method and device
US20210406016A1 (en) Matrix data scatter and gather by row
CN114461274A (en) Instruction processing apparatus, method, chip, computer device, and storage medium
CN109388645B (en) Instruction execution method, instruction execution device, and storage medium

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
CP03 Change of name, title or address

Address after: 518000 Building 1901, 1902, 1903, Qianhai Kexing Science Park, Labor Community, Xixiang Street, Bao'an District, Shenzhen, Guangdong Province

Patentee after: Shenzhen Flash Scissor Intelligent Technology Co.,Ltd.

Address before: 518000 Unit 9ABCDE, Building 2, Haihong Industrial Plant Phase II, Haihong Industrial Plant, West Side of Xixiang Avenue, Labor Community, Xixiang Street, Bao'an District, Shenzhen, Guangdong

Patentee before: Shenzhen big brother Technology Co.,Ltd.

CP03 Change of name, title or address