Never predict the changes in customer demand, even if the customer is my own

xiaoxiao2021-03-06  15

I wrote a software that accelerates the speed of the code. Flashime

One of the data structures (CCANDBUF) stores buffers from multiple dictionaries.

When I design this data structure, I want to think that the type of buffer cannot be otherwise other than Vector, so I will define CCANDBUF's core data members as public, so the purpose is to It is convenient to sort the data.

Public: std :: vector _cand_buf; // t is a word type

When you actually use the words in the temporary dictionary, it is best to sign a color sign because only the words of the temporary dictionary can be deleted. However, the setting of the current data structure makes it no separately after reading the buffer from the word. I have to modify std :: vector _cand_buf;, it can accommodate some marker.

So I have to revert_cand_buf to private data members. Then put access to _cand_buf is encapsulated by excuses. Otherwise I modified _cand_buf's type involved many of the code of the entire program.

#include #include

// Warning: T Must Support Value Copy Template Class ccandbuf {public: ccandbuf (unsigned int p = 9): _ selected (0) {_pagesize = (p> 9? 9: p);}

Unsigned long size () {return_cand_buf.size ();} void clear () {_cand_buf.clear (); _selected = 0; _cand_buf.reserve (1024);} BOOL EMPTY () {Return_cand_buf.empty (); void push_back (const T & e) {_cand_buf.push_back (e);} const T & get_elem (unsigned int i) {return _cand_buf;} unsigned int selected () {return _selected;} unsigned int selected_page_start () {return _selected / _pagesize * _pagesize;} unsigned int selected_page_end () {return _pagesize selected_page_start ()> _ cand_buf.size () _ cand_buf.size (): _ pagesize selected_page_start ();} void set_selected (unsigned int i) {_selected = i;} unsigned int? PageSize () {return_pagesize;

Void filter_self (Bool (* is_removable) ({std :: vector :: item new_end = std :: remove_if (_cand_buf.begin (), _nd_buf.end (), is_removable); _ Cand_buf.rase (new_end) _cand_buf.end ()); _ Cand_buf.reserve (1024); _ selected = 0;}

Void Sort (Bool (* less_cand) (T, T, T, T)) {std :: sort (_cand_buf.begin (), _ Cand_buf.end (), Less_cand);

PRIVATE: Std :: Vector _cand_buf;

转载请注明原文地址:https://www.9cbs.com/read-46703.html

New Post(0)