CN111310076A - Geographic position query method, device, medium and electronic equipment - Google Patents

Geographic position query method, device, medium and electronic equipment Download PDF

Info

Publication number
CN111310076A
CN111310076A CN202010114519.8A CN202010114519A CN111310076A CN 111310076 A CN111310076 A CN 111310076A CN 202010114519 A CN202010114519 A CN 202010114519A CN 111310076 A CN111310076 A CN 111310076A
Authority
CN
China
Prior art keywords
address
index
resident memory
memory block
data
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
CN202010114519.8A
Other languages
Chinese (zh)
Other versions
CN111310076B (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.)
Tongdun Holdings Co Ltd
Original Assignee
Tongdun Holdings 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 Tongdun Holdings Co Ltd filed Critical Tongdun Holdings Co Ltd
Priority to CN202010114519.8A priority Critical patent/CN111310076B/en
Publication of CN111310076A publication Critical patent/CN111310076A/en
Application granted granted Critical
Publication of CN111310076B publication Critical patent/CN111310076B/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/953Querying, e.g. by the use of web search engines
    • G06F16/9537Spatial or temporal dependent retrieval, e.g. spatiotemporal queries
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/29Geographical information databases
    • 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

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

Abstract

The embodiment of the disclosure provides a geographic position query method, a geographic position query device, a computer readable storage medium and electronic equipment, and relates to the technical field of computers, wherein the method comprises the following steps: acquiring an ip address; the method comprises the steps of obtaining a resident memory block and an index which are in an inquiry state in a system memory, wherein the system memory comprises two resident memory blocks, and the state of the resident memory block is converted among the following three states: updating, inquiring and idling, wherein the indexes comprise a primary index and a secondary index; inquiring the secondary index according to the ip address to obtain a primary index corresponding to the ip address; and inquiring the primary index according to the ip address to obtain the address offset of the geographic position data matched with the ip address. In the technical scheme of the embodiment of the disclosure, by setting two resident memory blocks and designing a secondary index structure, a large amount of memory occupied when the ip data is updated can be avoided, and the query efficiency is improved.

Description

Geographic position query method, device, medium and electronic equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a geographic location query method, an apparatus, a computer-readable storage medium, and an electronic device.
Background
With the rapid development of communication technology and the popularization of mobile internet, some lawless persons bypass the conventional wind control system detection by technical means such as ip address replacement and the like to carry out lawless acts such as pulling wool and the like which damage the rights and interests of merchants.
The ip address is called an internet protocol address, the ip address is an address of the device in the network, and the actual location of the device can be queried through the ip address, for example, the location of the address of 10.10.10.10 is found in china, zhejiang, hang, hough, and xx streets. The technology for inquiring the geographic position through the ip address can be applied to the aspects of anti-fraud, network performance optimization, network security, social network, e-commerce oriented marketing and the like.
The traditional method for querying the geographic position data is to construct a binary search tree through an ip address, but the geographic position corresponding to the ip address is frequently changed, so the binary search tree needs to be updated. When the binary search tree is updated, a large number of objects can be generated, so that garbage collection is frequent, and due to the fact that the garbage collection consumes a long time, the query efficiency is reduced due to frequent garbage collection.
How to improve the efficiency of geographic location query is a technical problem which needs to be solved urgently at present.
It is to be noted that the information disclosed in the above background section is only for enhancement of understanding of the background of the present disclosure, and thus may include information that does not constitute prior art known to those of ordinary skill in the art.
Disclosure of Invention
An object of the embodiments of the present disclosure is to provide a method and an apparatus for querying a geographic location, a computer-readable storage medium, and an electronic device, so as to improve efficiency of querying the geographic location at least to a certain extent.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows, or in part will be obvious from the description, or may be learned by practice of the disclosure.
According to a first aspect of the embodiments of the present disclosure, a geographic location query method is provided, including: acquiring an ip address; the method comprises the steps of obtaining a resident memory block and an index which are in an inquiry state in a system memory, wherein the system memory comprises two resident memory blocks, and the states of the resident memory blocks are converted among the following three states: updating, inquiring and idling, wherein the indexes comprise a primary index and a secondary index; inquiring the secondary index according to the ip address to obtain a primary index corresponding to the ip address; and inquiring the primary index according to the ip address to obtain the address offset of the geographic position data matched with the ip address.
In some embodiments, the method comprises: acquiring a current resident memory block in an idle state in the system memory, and setting the state of the current resident memory block as updating; storing ip data into the current resident memory block, wherein the ip data comprises an ip address and geographical position data corresponding to the ip address; establishing the index for the ip data stored in the current resident memory block, wherein the index comprises a primary index and a secondary index; and setting the state of the current resident memory block as query, and setting the state of another resident memory block in the system memory as idle.
In some embodiments, after querying the primary index according to the ip address, the method further comprises: acquiring an original byte array of the geographic position data according to the address offset; and analyzing the original byte array, and returning the geographic position data corresponding to the ip address to the client.
In some embodiments, the indexing the ip data stored in the current resident memory block includes: and establishing the index for the ip data stored in the current resident memory block by adopting a B + tree data structure.
In some embodiments, the method comprises: the size of the resident memory block is 700 MB.
In some embodiments, the key of the primary index is an ip address, and the value of the primary index is an address where the geographic location data corresponding to the ip address starts and ends in the resident memory block where the geographic location data corresponds to.
In some embodiments, the key of the secondary index is an ip address, and the value of the secondary index is a memory address of the primary index.
In some embodiments, the storing the ip data into the current resident memory block includes: and storing the ip data into the current resident memory block in a byte array mode.
In some embodiments, the returning the geographic location data corresponding to the ip address to the client further includes: and JSON packaging the geographic position data and returning to the client.
According to a second aspect of the embodiments of the present disclosure, there is provided a geographic location query device, including: the ip address acquisition unit is used for acquiring an ip address; the system memory comprises two resident memory blocks, and the states of the resident memory blocks are converted among the following three states: updating, inquiring and idling, wherein the indexes comprise a primary index and a secondary index; the second-level query unit is used for querying the second-level index according to the ip address to obtain a first-level index corresponding to the ip address; and the primary query unit is used for querying the primary index according to the ip address to obtain the address offset of the geographic position data matched with the ip address.
According to a third aspect of embodiments of the present disclosure, there is provided a computer-readable storage medium, on which a computer program is stored, which when executed by a processor, implements the geographical location query method according to the first aspect of the embodiments.
According to a fourth aspect of the embodiments of the present disclosure, there is provided an electronic apparatus including: one or more processors; a storage device for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement the geographical location query method as described in the first aspect of the embodiments above.
The technical scheme provided by the embodiment of the disclosure can have the following beneficial effects:
in the technical solutions provided in some embodiments of the present disclosure, by setting two resident memory blocks and designing a secondary index structure, it is possible to query the geographic position data corresponding to the ip address without parsing the ip data, thereby avoiding occupying a large amount of memory when updating the ip data, and improving the query efficiency.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure. It is to be understood that the drawings in the following description are merely exemplary of the disclosure, and that other drawings may be derived from those drawings by one of ordinary skill in the art without the exercise of inventive faculty. In the drawings:
FIG. 1 schematically shows a flow diagram of a geographic location query method according to an embodiment of the disclosure;
FIG. 2 is a diagram schematically illustrating a transition of a resident memory block between three states, according to an embodiment of the present disclosure;
fig. 3 schematically shows a flow chart for updating ip data according to an embodiment of the present disclosure;
FIG. 4 schematically illustrates a schematic diagram of a B + tree data structure according to an embodiment of the present disclosure;
FIG. 5 schematically illustrates a B + tree storing data according to an embodiment of the disclosure;
FIG. 6 schematically shows a schematic diagram of a one-level retrieval architecture according to an embodiment of the present disclosure;
FIG. 7 schematically shows a schematic diagram of a two-level retrieval structure according to an embodiment of the present disclosure;
FIG. 8 is a diagram that schematically illustrates state transitions of two memory resident blocks, in accordance with an embodiment of the present disclosure;
FIG. 9 schematically illustrates a block diagram of a geographic location query device according to one embodiment of the present disclosure;
FIG. 10 schematically illustrates a block diagram of a computer system suitable for use with an electronic device that implements an embodiment of the disclosure.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art.
Furthermore, the described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of embodiments of the disclosure. One skilled in the relevant art will recognize, however, that the subject matter of the present disclosure can be practiced without one or more of the specific details, or with other methods, components, devices, steps, and so forth. In other instances, well-known methods, devices, implementations, or operations have not been shown or described in detail to avoid obscuring aspects of the disclosure.
The block diagrams shown in the figures are functional entities only and do not necessarily correspond to physically separate entities. I.e. these functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor means and/or microcontroller means.
The flow charts shown in the drawings are merely illustrative and do not necessarily include all of the contents and operations/steps, nor do they necessarily have to be performed in the order described. For example, some operations/steps may be decomposed, and some operations/steps may be combined or partially combined, so that the actual execution sequence may be changed according to the actual situation.
In the related technology, when the geographic position corresponding to the ip address is queried according to the query ip address, the ip data needs to be parsed in advance, and the parsed ip data is stored in a memory for query. Therefore, a large amount of objects resident in the memory are generated when the ip data is updated, so that the system triggers garbage collection, and the query efficiency is reduced.
How to improve the efficiency of geographic location query is a technical problem which needs to be solved urgently at present.
In order to solve the above problem, an embodiment of the present disclosure provides a geographic location query method to improve efficiency of querying a geographic location.
Fig. 1 schematically illustrates a geographic location query method according to an exemplary embodiment of the present disclosure. The method provided by the embodiment of the present disclosure can be executed by any electronic device with computer processing capability, such as a terminal device and/or a server. Referring to fig. 1, a geographic location query method provided by an embodiment of the present disclosure may include the following steps:
step S102, the ip address is obtained.
Step S104, obtaining the resident memory block and the index in the query state in the system memory, where the system memory includes two resident memory blocks, and the state of the resident memory block is switched among the following three states: updating, inquiring and idling, wherein the index comprises a primary index and a secondary index.
And step S106, inquiring the secondary index according to the ip address to obtain the primary index corresponding to the ip address.
And step S108, inquiring the primary index according to the ip address to obtain the address offset of the geographic position data matched with the ip address.
In the technical scheme of the embodiment of the disclosure, two resident memory blocks are established in a system memory, and states of the two resident memory blocks are converted, so that one resident memory block is in an inquiry state, and the other resident memory block is in an update or idle state, which is equivalent to adopting a copy-on-write strategy, thereby reducing occupation of an application memory, and maintaining high-efficiency inquiry efficiency when ip data is updated. In addition, the technical scheme of the embodiment of the disclosure also establishes a secondary index for the data stored in the resident memory block, so that the query efficiency is accelerated.
Copy-on-write (COW) is an optimization strategy in the field of computer programming. The core idea is that if there are multiple callers (callers) requesting the same resource, such as memory or data storage on disk, they will get the same pointer to the same resource together, until a caller tries to modify the content of the resource, the system will not really copy a private copy (private copy) to the caller, but the original resource seen by other callers will remain unchanged. This process is transparent to other callers. The main advantage of this is that if the caller does not modify the resource, no copy (private copy) is created, so multiple callers can share the same resource just when reading.
Before step S102, two larger resident memory blocks need to be established, and the size of the resident memory block is selected according to the size of the ip data volume, for example, the size of the resident memory block may be 700 MB. The resident memory block can be switched between three states. The idle state indicates that the resident memory block is not used, the update state indicates that the resident memory block is in the ip data update process, and the query state indicates that the resident memory block is used for ip data query service. Here, the inquiry state belongs to an available state, and the idle state and the update state belong to an unavailable state. The conversion relationship between the three states of the resident memory block is shown in fig. 2.
After the resident memory block is established, the ip data needs to be stored in the resident memory. The ip data comprises an ip address and geographic position data corresponding to the ip address. Ip data is generally provided by related Ip manufacturers, and has the characteristics of high updating frequency and generally complete data volume. According to the ip data, the ip geographic position information can be effectively inquired. In the embodiment of the present disclosure, the IP data is generated based on IPv4, and IPv4 is a fourth version of Internet Protocol (IP).
As shown in fig. 3, when the ip data needs to be updated, the ip data may be stored in the idle resident memory block according to the following steps:
step S302 is to acquire a current resident memory block in an idle state in the system memory, and set the state of the current resident memory block to be updated.
In step S304, the ip data is stored in the current resident memory block.
Step S306, an index is established for the ip data stored in the current resident memory block, where the index includes a primary index and a secondary index.
Step S308, the state of the current resident memory block is set as query, and the state of another resident memory block in the system memory is set as idle.
In step S304, when the ip data is stored in the current resident memory block, the ip data is stored in the current resident memory block in the form of a byte array.
In step S306, after the ip data is stored in the current resident memory block, a B + tree data structure may be used to establish two levels of indexes for the ip data stored in the current resident memory block.
The B + tree is a tree data structure that is typically used in the file system of databases and operating systems. The B + tree is characterized in that data can be kept stable and orderly, and the insertion and modification of the B + tree have stable logarithmic time complexity. The time complexity of the query is O (logn), and the time complexity of the data insertion is O (logn), wherein n is the number of nodes.
The nodes in the B + tree are typically represented as an ordered set of elements and child pointers. If the order of this B + tree is m, there are at most m child pointers for any node. The number of child pointers is always the same as the number of elements for all internal nodes. As shown in FIG. 4, all leaves are at the same height, and the leaf nodes themselves are linked by key size from small to large.
When inserting data into the B + tree, the position of the node to be inserted therein is first found, and then a value is inserted into this node. If no node is in the violation state, the process ends. If a node has too many elements, it is split into two nodes, each with a minimum number of elements. This process continues recursively up the tree until the root node is reached, and if the root node is split, a new root node is created. In order for it to work, the minimum and maximum number of elements typically must be chosen such that the minimum number is no less than half of the maximum number.
When data is queried in a B + tree, the tree is traversed from top to bottom starting from a root node, and child pointers of which separation values are on any side of a value to be searched are selected. Binary search is typically used within a node to determine the location of data.
The embodiment of the disclosure combines the copy-on-write technology and the B + tree search, optimizes the index structure, establishes two-stage indexes, and accelerates the query efficiency.
When an index is established for the ip data, a primary index is established first. The data structure adopted by the first-level index is a B + tree, and the number of nodes of each tree is fixed. The key of the first-level index is an ip address, and the value of the first-level index is the address where the geographic position data corresponding to the ip address starts and ends in the memory block.
For example, for ip segments 000.000.000-000.255.255.255, we can obtain the structure shown in FIG. 5 (0 and n are array indices), where 0 is 0, start is 0, and end is n.
After the first-level indexes are established for all the ip, a plurality of B + trees shown in fig. 6 are obtained, the key of the node is the ip address, the value is the start and end addresses of the ip in the memory address, and it should be noted that the ip address of each root node is the minimum value in the tree.
When a certain ip needs to be queried, the tree where the ip is located needs to be determined quickly, and if a traversal method is used, the efficiency is low. According to the characteristics of the B + tree, when a certain ip address marked as x needs to be queried, the ip address is converted into an integer with a value of 50. Since the root node value of the upper graph B tree is 100 and the root node value of the A tree is 0, x must be in the A tree.
According to this feature, a secondary index as shown in fig. 7 can be built on the basis of the primary index.
The data structure of the secondary index can also be a B + tree, the key of the secondary index is an ip address, and the value of the secondary index is a memory address of the primary index.
In step S308, as shown in fig. 8, the updated state of the resident memory block is modified to be the query, and the state of another resident memory block is modified to be idle, so that the updated resident memory block can provide the query service. By repeating the process, the two resident memory blocks can be used alternately, so that the purpose of reducing resource utilization is achieved. As shown in fig. 8, the memory blocks-a and-B represent two alternative resident memory blocks, where a memory block filled with a vertical stripe indicates that the resident memory block is in an inquiry state, a memory block without filling indicates that the resident memory block is in an idle state, and a memory block filled with a horizontal stripe indicates that the resident memory block is in an update state.
After step S108, an original byte array of the geographic position data may be obtained according to the address offset, and the original byte array may be analyzed, and the geographic position data corresponding to the ip address may be returned to the client.
When the geographic position data corresponding to the ip address is returned to the client, JSON encapsulation can be carried out on the geographic position data and then the geographic position data is returned to the client. JSON encapsulation is JSON serialization.
According to the geographic position query method, the two resident memory blocks are arranged and the secondary index structure is designed, so that the geographic position data corresponding to the ip address can be queried without analyzing the ip data, a large amount of memory is prevented from being occupied when the ip data are updated, and the query efficiency is improved.
The following describes embodiments of the apparatus of the present disclosure, which may be used to perform the above-mentioned geographic location query method of the present disclosure. As shown in fig. 9, a geographic location query device 600 provided according to an embodiment of the present disclosure may include:
an ip address obtaining unit 602, configured to obtain an ip address.
A memory obtaining unit 604, configured to obtain a resident memory block and an index in a system memory in an inquiry state, where the system memory includes two resident memory blocks, and a state of the resident memory block is converted between the following three states: updating, inquiring and idling, wherein the index comprises a primary index and a secondary index.
And the secondary query unit 606 is configured to query the secondary index according to the ip address to obtain a primary index corresponding to the ip address.
The primary query unit 608 is configured to query the primary index according to the ip address to obtain an address offset of the geographic location data matched with the ip address.
In the technical scheme of the embodiment of the disclosure, two resident memory blocks are established in a system memory, and states of the two resident memory blocks are converted, so that one resident memory block is in an inquiry state, and the other resident memory block is in an update or idle state, which is equivalent to adopting a copy-on-write strategy, thereby reducing occupation of an application memory, and maintaining high-efficiency inquiry efficiency when ip data is updated. In addition, the technical scheme of the embodiment of the disclosure also establishes a secondary index for the data stored in the resident memory block, so that the query efficiency is accelerated.
In another embodiment of the present invention, the geographic location query device not only includes the ip address obtaining unit 302, the memory obtaining unit 304, the secondary query unit 306, and the primary query unit 308 in the geographic location query device 600, but also includes a state updating unit, an ip data storing unit, an index establishing unit, and a returning unit, where:
the state updating unit is used for acquiring the current resident memory block in an idle state in the system memory and setting the state of the current resident memory block as updating.
The ip data storage unit is used for storing the ip data into the current resident memory block.
The index establishing unit is used for establishing an index for the ip data stored in the current resident memory block, and the index comprises a primary index and a secondary index.
The state updating unit is further configured to set the state of the current resident memory block to be queried, and set the state of another resident memory block in the system memory to be idle.
And the return unit is used for acquiring the original byte array of the geographic position data according to the address offset, analyzing the original byte array and returning the geographic position data corresponding to the ip address to the client.
As each functional module of the geographic position query device in the exemplary embodiment of the present disclosure corresponds to the step of the exemplary embodiment of the geographic position query method, please refer to the above-mentioned embodiment of the geographic position query method in the present disclosure for details that are not disclosed in the embodiment of the apparatus of the present disclosure.
The geographic position query device provided by the embodiment of the disclosure can query the geographic position data corresponding to the ip address without analyzing the ip data by setting the two resident memory blocks and designing the secondary index structure, thereby avoiding occupying a large amount of memory when updating the ip data and improving the query efficiency.
Referring now to FIG. 10, shown is a block diagram of a computer system 700 suitable for use in implementing the electronic devices of embodiments of the present disclosure. The computer system 700 of the electronic device shown in fig. 10 is only an example, and should not bring any limitations to the function and scope of use of the embodiments of the present disclosure.
As shown in fig. 10, the computer system 700 includes a Central Processing Unit (CPU)701, which can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. In the RAM 703, various programs and data necessary for system operation are also stored. The CPU701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input/output (I/O) interface 707 is also connected to bus 704.
The following components are connected to the I/O interface 707: an input portion 706 including a keyboard, a mouse, and the like; an output section 707 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 708 including a hard disk and the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. The communication section 709 performs communication processing via a network such as the internet. A drive 710 is also connected to the I/O interface 705 as needed. A removable medium 711 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 710 as necessary, so that a computer program read out therefrom is mounted into the storage section 708 as necessary.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable storage medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 709, and/or installed from the removable medium 711. The computer program executes the above-described functions defined in the system of the present application when executed by the Central Processing Unit (CPU) 701.
It should be noted that the computer readable storage medium shown in the present disclosure may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer-readable signal medium may include a propagated data signal with computer-readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable storage medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable storage medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software, or may be implemented by hardware, and the described units may also be disposed in a processor. Wherein the names of the elements do not in some way constitute a limitation on the elements themselves.
As another aspect, the present application also provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments; or may exist separately without being assembled into the electronic device. The computer-readable storage medium carries one or more programs which, when executed by an electronic device, cause the electronic device to implement the geographical location query method as described in the above embodiments.
For example, the electronic device may implement the following as shown in fig. 1: step S102, acquiring an ip address; step S104, obtaining a resident memory block and an index in a system memory in an inquiry state, where the system memory includes two resident memory blocks, and the states of the resident memory blocks are switched among the following three states: updating, inquiring and idling, wherein the indexes comprise a primary index and a secondary index; step S106, inquiring the secondary index according to the ip address to obtain a primary index corresponding to the ip address; and S108, inquiring the primary index according to the ip address to obtain the address offset of the geographic position data matched with the ip address.
It should be noted that although in the above detailed description several modules or units of the device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit, according to embodiments of the present disclosure. Conversely, the features and functions of one module or unit described above may be further divided into embodiments by a plurality of modules or units.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (which may be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which may be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the embodiments of the present disclosure.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It will be understood that the present disclosure is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (12)

1. A method for geographic location query, the method comprising:
acquiring an ip address;
the method comprises the steps of obtaining a resident memory block and an index which are in an inquiry state in a system memory, wherein the system memory comprises two resident memory blocks, and the states of the resident memory blocks are converted among the following three states: updating, inquiring and idling, wherein the indexes comprise a primary index and a secondary index;
inquiring the secondary index according to the ip address to obtain a primary index corresponding to the ip address;
and inquiring the primary index according to the ip address to obtain the address offset of the geographic position data matched with the ip address.
2. The method according to claim 1, characterized in that it comprises:
acquiring a current resident memory block in an idle state in the system memory, and setting the state of the current resident memory block as updating;
storing ip data into the current resident memory block, wherein the ip data comprises an ip address and geographical position data corresponding to the ip address;
establishing the index for the ip data stored in the current resident memory block, wherein the index comprises a primary index and a secondary index;
and setting the state of the current resident memory block as query, and setting the state of another resident memory block in the system memory as idle.
3. The method of claim 1, wherein after querying the primary index according to the ip address, the method further comprises:
acquiring an original byte array of the geographic position data according to the address offset;
and analyzing the original byte array, and returning the geographic position data corresponding to the ip address to the client.
4. The method according to claim 2, wherein said indexing the ip data stored in the current resident memory block comprises:
and establishing the index for the ip data stored in the current resident memory block by adopting a B + tree data structure.
5. The method of claim 1, wherein the size of the memory resident block is 700 MB.
6. The method according to claim 1, wherein the key of the primary index is an ip address, and the value of the primary index is an address where the geographic location data corresponding to the ip address starts and ends in the resident memory block where the geographic location data corresponds to.
7. The method of claim 1,
the key of the secondary index is an ip address, and the value of the secondary index is a memory address of the primary index.
8. The method according to claim 2, wherein the storing ip data into the current resident memory block comprises:
and storing the ip data into the current resident memory block in a byte array mode.
9. The method according to claim 3, wherein the returning the geographic location data corresponding to the ip address to the client further comprises:
and JSON packaging the geographic position data and returning to the client.
10. A geographic location query device, comprising:
the ip address acquisition unit is used for acquiring an ip address;
the system memory comprises two resident memory blocks, and the states of the resident memory blocks are converted among the following three states: updating, inquiring and idling, wherein the indexes comprise a primary index and a secondary index;
the second-level query unit is used for querying the second-level index according to the ip address to obtain a first-level index corresponding to the ip address;
and the primary query unit is used for querying the primary index according to the ip address to obtain the address offset of the geographic position data matched with the ip address.
11. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the geographical location query method according to any one of claims 1 to 9.
12. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement the geographical location query method of any one of claims 1-9.
CN202010114519.8A 2020-02-25 2020-02-25 Geographic position query method, geographic position query device, geographic position query medium and electronic equipment Active CN111310076B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010114519.8A CN111310076B (en) 2020-02-25 2020-02-25 Geographic position query method, geographic position query device, geographic position query medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010114519.8A CN111310076B (en) 2020-02-25 2020-02-25 Geographic position query method, geographic position query device, geographic position query medium and electronic equipment

Publications (2)

Publication Number Publication Date
CN111310076A true CN111310076A (en) 2020-06-19
CN111310076B CN111310076B (en) 2023-10-03

Family

ID=71161881

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010114519.8A Active CN111310076B (en) 2020-02-25 2020-02-25 Geographic position query method, geographic position query device, geographic position query medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN111310076B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112948376A (en) * 2021-02-02 2021-06-11 厦门服云信息科技有限公司 IP geographical position information query method, terminal equipment and storage medium
CN115396395A (en) * 2022-08-25 2022-11-25 北京发现角科技有限公司 Method and device for determining geographic position of IP address

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2001044987A2 (en) * 1999-12-16 2001-06-21 Gligorov, Monika Parallel data access procedure for b-tree structures
CN101183369A (en) * 2007-12-11 2008-05-21 中山大学 Embedded electronic dictionary word stock structure
CN103561133A (en) * 2013-11-19 2014-02-05 中国科学院计算机网络信息中心 IP address ownership information indexing and fast querying method
CN105159895A (en) * 2014-05-28 2015-12-16 国际商业机器公司 Method and system for storing and inquiring data
US20190362000A1 (en) * 2018-05-25 2019-11-28 TmaxData Co., Ltd. Method and apparatus for providing efficient indexing and computer program included in computer readable medium therefor
CN110633296A (en) * 2018-05-31 2019-12-31 北京京东尚科信息技术有限公司 Data query method, device, medium and electronic equipment

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2001044987A2 (en) * 1999-12-16 2001-06-21 Gligorov, Monika Parallel data access procedure for b-tree structures
CN101183369A (en) * 2007-12-11 2008-05-21 中山大学 Embedded electronic dictionary word stock structure
CN103561133A (en) * 2013-11-19 2014-02-05 中国科学院计算机网络信息中心 IP address ownership information indexing and fast querying method
CN105159895A (en) * 2014-05-28 2015-12-16 国际商业机器公司 Method and system for storing and inquiring data
US20190362000A1 (en) * 2018-05-25 2019-11-28 TmaxData Co., Ltd. Method and apparatus for providing efficient indexing and computer program included in computer readable medium therefor
CN110633296A (en) * 2018-05-31 2019-12-31 北京京东尚科信息技术有限公司 Data query method, device, medium and electronic equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
喻波等: "一种基于共享前缀的两级索引结构" *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112948376A (en) * 2021-02-02 2021-06-11 厦门服云信息科技有限公司 IP geographical position information query method, terminal equipment and storage medium
CN115396395A (en) * 2022-08-25 2022-11-25 北京发现角科技有限公司 Method and device for determining geographic position of IP address
CN115396395B (en) * 2022-08-25 2023-05-12 北京发现角科技有限公司 Method and device for determining geographic position of IP address

Also Published As

Publication number Publication date
CN111310076B (en) 2023-10-03

Similar Documents

Publication Publication Date Title
US20170116244A1 (en) Bloom filter index for device discovery
CN109614402B (en) Multidimensional data query method and device
CN108959244A (en) The method and apparatus of address participle
CN106407303A (en) Data storage method and apparatus, and data query method and apparatus
CN111447257B (en) Message conversion method and device
CN111629081A (en) Internet protocol IP address data processing method and device and electronic equipment
CN112579610A (en) Multi-data source structure analysis method, system, terminal device and storage medium
CN111310076B (en) Geographic position query method, geographic position query device, geographic position query medium and electronic equipment
CN110807028B (en) Method, apparatus and computer program product for managing a storage system
CN110795069A (en) Code analysis method, intelligent terminal and computer readable storage medium
CN113704307A (en) Data query method, device, server and computer readable storage medium
CN108154024B (en) Data retrieval method and device and electronic equipment
CN114139040A (en) Data storage and query method, device, equipment and readable storage medium
CN111368227A (en) URL processing method and device
CN108959294B (en) Method and device for accessing search engine
CN113434506B (en) Data management and retrieval method, device, computer equipment and readable storage medium
CN115039090A (en) Data query method, device, server and storage medium
CN111949648B (en) Memory data caching system and data indexing method
CN107977381B (en) Data configuration method, index management method, related device and computing equipment
CN110471708B (en) Method and device for acquiring configuration items based on reusable components
CN113779025A (en) Optimization method, system and application of classified data retrieval efficiency in block chain
CN112818710A (en) Method and device for processing asynchronous network machine translation request
CN113364895A (en) Method, device, electronic equipment and storage medium for resource scheduling
CN112988778A (en) Method and device for processing database query script
CN115396395B (en) Method and device for determining geographic position of IP address

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