In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
What is a table driver: replace complex logical structures such as if by looking up data tables. Else., switch, etc.)
The advantages of table driver are as follows: 1. Adjust the focus of programming to solving problems rather than complex logical judgments.
2. Increase the flexibility of the program, easy to add, easy to modify
3. Data-driven. If the data is written to a file and read from the file every time it is started, then, if you want to modify some variables, you may modify the data file directly instead of modifying the program structure.
There are three table-driven methods:
1. Direct drive method: what you need to find, specify the index, and you can immediately return the corresponding elements or actions of the index in the table.
Case 1: (one-dimensional search: that is, one-dimensional search can replace a layer of if structure or switch structure): for example, you want to find the number of days per month in December, as follows: month_day [12] = {31 minus 30 minus 29 minus 30 pence 31 pencils 31 pence 31 pens 30 pr 30} Return month_day [5]; this directly corresponds to the number of days in May Direct drive means that the index corresponds directly to the required data or actions. Case 2: (3D search: that is, there are three conditions at the same time, if you use if or switch, you may need a three-tier nested structure) for example, the price of a ticket is determined by gender, student, and disability. Then, we can use 3D data-driven tables instead of complex upper-level if statements. Int entrance_ticket_fee [] = {0jue 10}, {0je 15}}, {{0jue 15}, {15pm 30} this is a three-dimensional vector. The three dimensions represent different limitations, with the first dimension representing gender, index 0 representing female and 1 representing male. The second dimension represents whether it is a student, index 0 represents yes, index 1 represents no, the third dimension represents disability, index 0 represents disability, index 1 represents health. The above three-dimensional array represents: girl, student, disabled 0 yuan girl, student, healthy 10 yuan. Girls, non-students, disability 0 yuan; girls, non-students, very urgent 15 yuan; boys, students, disability 0 yuan Boy, student, health, 15 yuan; boy, non-student, disability 15 yuan; boy, non-student, health, 30 yuan The return value is determined by giving gender, whether a student is disabled, or not; return entrance_ticket_fee [0] [1] [1] / / 15 yuan 2. Index-driven method: due to many cases, when there are segments, the situation is different. For example, according to age, tickets for people under 18 and over 60 are halved according to the standard, while those between 19 and 59 are reduced by half. If the ticket corresponds to the age, then, if the direct index method is still used, if there is a value for 0 Murray under 18 years old and over 60 years old, then it can actually be replaced by an index, thus saving space. This transformation is realized through functions. Index-driven is an improvement of direct-driven method in saving space. 3. Ladder access list: many problems do not need to be one-on-one, but need to be classified, simple examples For example, by grade: 100-90: a 89-80: B 79-60: C 59-0: d given a number Determine its scope, that is, it can be accessed by the cloud ladder. Ladder access is made by comparing the number of data to be compared (original data) with the upper (or lower) limit of each region, either sequentially or by dichotomy. Ladder access is another improvement on the index-driven method in saving memory space.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.