A DFA algorithm-based card bin matching method and system
By constructing a card bin dictionary using the DFA algorithm, the problems of frequent database access and low efficiency in card number lookup in existing technologies are solved. This enables accurate and efficient card bin matching with hundreds of millions of data points, improving system performance and cache hit rate.
Patent Information
- Application Number
- CN202211441202.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-17
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2042-11-17
AI Technical Summary
Existing technologies for card number lookup suffer from problems such as frequent database access, excessive memory consumption, increased machine load, low efficiency, and low hit rate due to a large number of queries. In particular, it is difficult to achieve accurate and efficient card bin matching when dealing with hundreds of millions of data points.
A card bin dictionary is constructed using the DFA algorithm. By matching card numbers with the card bin database, database queries are reduced and matching efficiency is improved. The DFA algorithm is used to determine a finite automaton, which further enhances the card bin matching performance.
It achieves accurate and efficient card bin matching with hundreds of millions of data points, reduces database access, improves system performance and cache hit rate, and enhances the system's anti-concurrency capability.
Smart Images

Figure CN115729966B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of Internet technology, and more specifically, to a card bin matching method and system based on the DFA algorithm. Background Technology
[0002] With the rapid development of the internet and the increasing number of netizens, the internet boom has arrived, and the scale of online shopping users in China continues to rise. Due to the widespread adoption of the internet, the advantages of online shopping have become more prominent, increasingly becoming an important form of shopping. Business applications, represented by online shopping, online payment, and travel booking, continue to grow rapidly and lead the development of other internet applications, becoming a prominent feature of internet development. Card binding for payment has become a prerequisite for shopping. In the transaction chain, identifying the issuing institution of a bank card through its card number and using the card's BIN to access different clearing organizations are basic requirements. Among single-pattern matching algorithms, classic ones include the BF algorithm, KMP algorithm, and BM algorithm; among multi-pattern matching algorithms, classic ones include the AC algorithm, CW algorithm, and WM algorithm. These algorithms suffer from problems such as high time complexity, slow matching speed in practical applications, poor flexibility, and difficulty in practical application.
[0003] Existing technologies for querying card bins using card numbers commonly encounter three problems: a) High volume of queries: With over ten million daily active queries, numerous database accesses, frequent connections and closures lead to excessive I / O, high memory consumption, and increased machine load. b) Inefficiency: The database can easily become a bottleneck for system performance. Single-machine storage capacity, I / O, and CPU processing power are all limited. When the data volume of a single table reaches 10 million or 100GB, CRUD operations face a significant performance drop. c) Low hit rate: With over one hundred million card number data points and only over twenty thousand matching card bin data points, using card numbers as Redis keys for caching results in a low cache hit rate. Generally, a higher cache hit rate indicates greater benefits from caching, better application performance (shorter response time, higher throughput), and stronger concurrency resistance.
[0004] Currently, there is a need for a card bin matching method based on the DFA algorithm, which can achieve accurate and efficient card bin matching and avoid the problem of brute-force database queries. Summary of the Invention
[0005] The purpose of this invention is to provide a card bin matching method based on the DFA algorithm, which can construct a card bin dictionary through a card bin database and perform DFA algorithm matching on card numbers, thereby achieving accurate and efficient matching of card bins under a data volume of hundreds of millions, avoiding the problem of brute-force database queries.
[0006] Another objective of this invention is to provide a card bin matching system based on the DFA algorithm, which can construct a card bin thesaurus through a card bin database and perform DFA algorithm matching on card numbers, thereby achieving accurate and efficient matching of card bins under a data volume of hundreds of millions, avoiding the problem of brute-force database queries.
[0007] The embodiments of the present invention are implemented as follows:
[0008] In a first aspect, embodiments of this application provide a card bin matching method based on the DFA algorithm, which includes the following steps: S1 Determine the finite automaton construction stage: construct a card bin library and cache the card bin information in the database locally; S2 Store the information in the local cache and construct a card bin dictionary: a. When the service starts and initializes, first query the card bin information data in the database to obtain a list set; b. Traverse the list set, take the card bin as the key and the entity data as the value; c. For card bins greater than or equal to 6 characters, truncate the first 6 characters as the key, and for card bins less than 6 characters, directly use them as the key; d. First determine if there is a key. When there is no key, use the newly created list set as the value and put it into the card bin dictionary in reverse order of card bin length; when there is a key, put the card bin data into the list set and store it into the card bin dictionary in reverse order of card bin length; e. The card bin dictionary is constructed; S3 Perform DFA matching on the card bin dictionary for the card number transmitted from the upstream.
[0009] In some embodiments of the present invention, step S3 specifically includes the following steps: a. First, the first 6 digits of the card number are extracted as the key for DFA matching. If the key matches successfully, the first item in the list of its values is retrieved. The card number reaches the termination state and the matching is successful, and the card bin information is returned; b. If the first 6 digits do not match, the first 5 digits are extracted as the key for DFA matching. If the key matches successfully, the first item in the list of its values is retrieved. The card number reaches the termination state and the matching is successful, and the card bin information is returned; c. If the first 5 digits do not match, the first 4 digits are extracted as the key for DFA matching. If the key matches successfully... If a match is found, retrieve the first item from the list of values, indicating the card number has reached the termination state and a successful match has been achieved. Return the card bin information. d. If the first 4 digits are not matched, use the first 3 digits as the key for a DFA match. If the key matches successfully, retrieve the first item from the list of values, indicating the card number has reached the termination state and a successful match has been achieved. Return the card bin information. e. If the first 3 digits are not matched, use the first 2 digits as the key for a DFA match. If the key matches successfully, retrieve the first item from the list of values, indicating the card number has reached the termination state and a successful match has been achieved. Return the card bin information. Otherwise, the card bin information does not exist.
[0010] In some embodiments of the present invention, in step S2 above, when constructing the card bin library, the card bin is transferred from the previous state as an independent state.
[0011] In some embodiments of the present invention, step S1 specifically includes the following steps: employing the DFA algorithm, including a finite set of states and multiple edges connecting one state to another, each edge marked with a symbol, the symbol containing either an initial state or a final state; each child node except the root node contains a character; from the root node to a certain node, the characters along the path are connected to form the string corresponding to that node; the common prefix of each word is stored as a character node; the finite state automaton A is determined to be: A = (Q, Σ, δ, Q0, F), where Q: a non-empty finite set of states, Σ: an input character table, δ: the transition function (Q, Σ) -> Q, Q0: the start state, and F: a set of accepting states.
[0012] Secondly, embodiments of this application provide a card bin matching system based on the DFA algorithm, implemented based on any of the methods described above in the first aspect.
[0013] Compared with the prior art, the embodiments of the present invention have at least the following advantages or beneficial effects:
[0014] 1. This application improves the performance of card bin matching by using the DFA algorithm to determine finite automata. Since the database is queried only when the service starts and cached locally, the large number of subsequent database accesses are reduced, resulting in a significant performance improvement.
[0015] 2. If the matched card number text is n, then the time complexity is O(n²), and the matching efficiency will not be affected even if the number of card numbers continues to increase. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a schematic diagram of step S2 in Embodiment 1 of the present invention;
[0018] Figure 2 This is a schematic diagram of step S3 in Embodiment 1 of the present invention;
[0019] Figure 3 This is a schematic diagram of step S1 in Embodiment 1 of the present invention;
[0020] Figure 4 This is a schematic diagram of the electronic device in Embodiment 2 of the present invention. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0022] Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0023] In the description of this application, it should also be noted that, unless otherwise explicitly specified and limited, the terms "set" and "connection" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances.
[0024] The following detailed description of some embodiments of this application is provided in conjunction with the accompanying drawings. Unless otherwise specified, the various embodiments and features described below can be combined with each other.
[0025] Example 1
[0026] Please see Figures 1-3 , Figures 1-3 The diagram illustrates a card bin matching method based on the DFA algorithm provided in this application embodiment. The card bin matching method based on the DFA algorithm includes the following steps: S1 Determine the finite automaton construction stage: Construct a card bin library and cache the card bin information in the database locally; S2 Store the information in the local cache and construct a card bin dictionary: a. During service startup initialization, first query the card bin information data in the database to obtain a list set; b. Traverse the list set, taking the card bin as the key and the entity data as the value; c. For card bins greater than or equal to 6 characters, truncate the first 6 characters as the key; for card bins less than 6 characters, use them directly as the key; d. First determine if there is a key. If there is no key, use the newly created list set as the value and add it to the card bin dictionary in reverse order of card bin length; if there is a key, add the card bin data to the list set and store it in the card bin dictionary in reverse order of card bin length; e. The card bin dictionary is constructed; S3 Perform DFA matching on the card bin dictionary for the card number transmitted from the upstream.
[0027] In some embodiments of the present invention, step S3 specifically includes the following steps: a. First, the first 6 digits of the card number are extracted as the key for DFA matching. If the key matches successfully, the first item in the list of its values is retrieved. The card number reaches the termination state and the matching is successful, and the card bin information is returned; b. If the first 6 digits do not match, the first 5 digits are extracted as the key for DFA matching. If the key matches successfully, the first item in the list of its values is retrieved. The card number reaches the termination state and the matching is successful, and the card bin information is returned; c. If the first 5 digits do not match, the first 4 digits are extracted as the key for DFA matching. If the key matches successfully... If a match is found, retrieve the first item from the list of values, indicating the card number has reached the termination state and a successful match has been achieved. Return the card bin information. d. If the first 4 digits are not matched, use the first 3 digits as the key for a DFA match. If the key matches successfully, retrieve the first item from the list of values, indicating the card number has reached the termination state and a successful match has been achieved. Return the card bin information. e. If the first 3 digits are not matched, use the first 2 digits as the key for a DFA match. If the key matches successfully, retrieve the first item from the list of values, indicating the card number has reached the termination state and a successful match has been achieved. Return the card bin information. Otherwise, the card bin information does not exist.
[0028] In some embodiments of the present invention, in step S2 above, when constructing the card bin library, the card bin is transferred from the previous state as an independent state.
[0029] In some embodiments of the present invention, step S1 specifically includes the following steps: employing the DFA algorithm, including a finite set of states and multiple edges connecting one state to another, each edge being marked with a symbol, which includes either an initial state or a final state; each child node except the root node contains a character; the characters along the path from the root node to a certain node are connected to form the string corresponding to that node; the common prefix of each word is stored as a character node; the finite state automaton A is determined to be: A = (Q, Σ, δ, Q0, F), where Q: a non-empty finite set of states, Σ: an input character table, δ: a transition function (Q, Σ) -> Q, Q0: the start state, and F: a set of accepting states.
[0030] This invention employs the Deterministic Finite Automaton (DFA) algorithm, also known as the Deterministic Finite Acceptor. This algorithm uses a finite set of states and edges connecting states, each marked with a symbol. Each edge contains either an initial state or a final state. Unlike indeterminate finite automata, in a DFA, no two edges originating from the same state will have the same symbol. In short, we can obtain the next state from the event and the current state: event + state = nextstate. The root node contains no characters, and each child node (excluding the root node) contains one character. Connecting the characters along the path from the root node to a given node forms the string corresponding to that node. The common prefix of each word is stored as a character node. The Deterministic Finite Automaton A can be written as: A = (Q, Σ, δ, Q0, F), where Q: a non-empty finite set of states, Σ: an input character list, δ: the transition function (Q, Σ) -> Q, Q0: the initial state, and F: a set of accepting states. Figure 3 In the diagram, the top-left automaton recognizes all binary strings containing at least one "00". The bottom-right automaton recognizes all binary strings with an even number of "1". The bottom-left automaton is the product of the first two languages and recognizes their intersection.
[0031] Example 2
[0032] Please see Figure 4 , Figure 4 This is a schematic structural block diagram of an electronic device provided in an embodiment of this application. The electronic device includes a memory 101, a processor 102, and a communication interface 103. The memory 101, processor 102, and communication interface 103 are electrically connected to each other directly or indirectly to realize data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines. The memory 101 can be used to store software programs and modules, such as the program instructions / modules for implementing the card bin matching system based on the DFA algorithm in Embodiment 1 of this application. The processor 102 executes various functional applications and data processing by executing the software programs and modules stored in the memory 101. The communication interface 103 can be used for signaling or data communication with other node devices.
[0033] The memory 101 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0034] The processor 102 can be an integrated circuit chip with signal processing capabilities. The processor 102 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0035] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0036] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0037] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0038] In summary, this application provides a card bin matching method and system based on the DFA algorithm. By employing the DFA algorithm to determine a finite automaton, the performance of card bin matching is improved. Since the database is queried and cached locally only during service startup, subsequent database accesses are reduced, resulting in a significant performance improvement. If the matched card number text is n, the time complexity is O(n²), and the matching efficiency remains unaffected even as the number of card numbers increases. A card bin thesaurus is constructed using the card bin database to perform DFA algorithm matching on card numbers, thus incorporating a filtering function within a sensitive word matching function.
[0039] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
[0040] It will be apparent to those skilled in the art that this application is not limited to the details of the exemplary embodiments described above, and that this application can be implemented in other specific forms without departing from the spirit or essential characteristics of this application. Therefore, the embodiments should be considered illustrative and non-limiting in all respects, and the scope of this application is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within this application. No reference numerals in the claims should be construed as limiting the scope of the claims.
Claims
1. A card bin matching method based on the DFA algorithm, characterized in that, Includes the following steps, S1 Determines the finite automaton construction phase: Build a card bin library and cache the card bin information in the database locally; S2 is then stored in the local cache to build the card bin dictionary: a. During service startup and initialization, first query the database card bin information data to obtain a list collection; b. Iterate through the list collection, taking the card bin as the key and the entity data as the value; c. For card bins of 6 or more digits, truncate the first 6 digits as the key; for card bins of less than 6 digits, use the first 6 digits directly as the key. d. First, check if there is a key. If there is no key, create a new list collection as the value and put it into the card bin dictionary in descending order of card bin length. If there is a key, put the card bin data into the list collection and store it into the card bin dictionary in descending order of card bin length. e. The Kabin thesaurus has been completed; S3 performs DFA matching on the card number transmitted from the upstream in the card bin dictionary; Specifically, the steps include the following: a. First, extract the first 6 digits of the card number as the key for DFA matching. If the key matches successfully, retrieve the first item of the list of its values. When the card number reaches the termination state and the match is successful, return the card bin information. b. If the first 6 digits are not matched, the first 5 digits are used as the key to perform a DFA match. If the key matches successfully, the first item of the value list is retrieved. If the card number reaches the termination state and the match is successful, the card bin information is returned. c. If the first 5 digits are not matched, the first 4 digits are used as the key to perform a DFA match. If the key matches successfully, the first item of the value list is retrieved. If the card number reaches the termination state and the match is successful, the card bin information is returned. d. If the first 4 digits are not matched, the first 3 digits are used as the key to perform a DFA match. If the key matches successfully, the first item of the value list is retrieved. If the card number reaches the termination state and the match is successful, the card bin information is returned. e. If the first 3 digits are not matched, the first 2 digits are used as the key for DFA matching. If the key matches successfully, the first item of the value list is retrieved. If the card number reaches the termination state and the matching is successful, the card bin information is returned; otherwise, the card bin information does not exist.
2. The card bin matching method based on the DFA algorithm as described in claim 1, characterized in that, In step S2, when constructing the card bin library, the card bin is treated as an independent state and transitioned from the previous 1s state.
3. The card bin matching method based on the DFA algorithm as described in claim 1, characterized in that, Step S1 specifically includes the following steps: using the DFA algorithm, there is a finite set of states and multiple edges from one state to another. Each edge is marked with a symbol, which includes either the initial state or the final state. Each child node except the root node contains a character. The characters along the path from the root node to a certain node are connected to form the string corresponding to that node. The common prefix of each word is stored as a character node. A deterministic finite state automaton A is represented as: A = (Q, Σ, δ, Qo, F), where Q is a non-empty finite set of states, Σ is an input character list, δ is the transition function (Q, Σ) -> Q, Qo is the start state, and F is a set of accepting states.
4. A card bin matching system based on the DFA algorithm, characterized in that... It is implemented based on the method described in any one of claims 1 to 3.
5. An electronic device, characterized in that, include: Memory, used to store one or more programs; processor; When the one or more programs are executed by the processor, the method described in claims 1 to 3 is implemented.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Card bin information storage method and device
CN111581448A
Method and apparatus for processing of finite automata
US20150186786A1