1/***************************************************************************** 2 3Copyright (c) 2011, 2018, Oracle and/or its affiliates. All Rights Reserved. 4 5This program is free software; you can redistribute it and/or modify it under 6the terms of the GNU General Public License, version 2.0, as published by the 7Free Software Foundation. 8 9This program is also distributed with certain software (including but not 10limited to OpenSSL) that is licensed under separate terms, as designated in a 11particular file or component or in included license documentation. The authors 12of MySQL hereby grant you an additional permission to link the program and 13your derivative works with the separately licensed software that they have 14included with MySQL. 15 16This program is distributed in the hope that it will be useful, but WITHOUT 17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, 19for more details. 20 21You should have received a copy of the GNU General Public License along with 22this program; if not, write to the Free Software Foundation, Inc., 2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 25*****************************************************************************/ 26 27/** @file include/fts0priv.ic 28 Full text search internal header file 29 30 Created 2011/11/12 Sunny Bains 31 ***********************************************************************/ 32 33/** Write the table id to the given buffer (including final NUL). Buffer must be 34 at least FTS_AUX_MIN_TABLE_ID_LENGTH bytes long. 35 @param[in] id a table/index id 36 @param[in] str buffer to write the id to 37 @return number of bytes written */ 38UNIV_INLINE 39int fts_write_object_id(ib_id_t id, char *str) { 40 return (sprintf(str, UINT64PFx, id)); 41} 42 43/** Read the table id from the string generated by fts_write_object_id(). 44 @return true if parse successful */ 45UNIV_INLINE 46ibool fts_read_object_id(ib_id_t *id, /* out: an id */ 47 const char *str) /* in: buffer to read from */ 48{ 49 /* NOTE: this func doesn't care about whether current table 50 is set with HEX_NAME, the user of the id read here will check 51 if the id is HEX or DEC and do the right thing with it. */ 52 return (sscanf(str, UINT64PFx, id) == 1); 53} 54 55/** Compare two fts_trx_table_t instances. 56 @return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */ 57UNIV_INLINE 58int fts_trx_table_cmp(const void *p1, /*!< in: id1 */ 59 const void *p2) /*!< in: id2 */ 60{ 61 const dict_table_t *table1 = 62 (*static_cast<const fts_trx_table_t *const *>(p1))->table; 63 64 const dict_table_t *table2 = 65 (*static_cast<const fts_trx_table_t *const *>(p2))->table; 66 67 return ((table1->id > table2->id) ? 1 : (table1->id == table2->id) ? 0 : -1); 68} 69 70/** Compare a table id with a fts_trx_table_t table id. 71 @return < 0 if n1 < n2, 0 if n1 == n2,> 0 if n1 > n2 */ 72UNIV_INLINE 73int fts_trx_table_id_cmp(const void *p1, /*!< in: id1 */ 74 const void *p2) /*!< in: id2 */ 75{ 76 const uintmax_t *table_id = static_cast<const uintmax_t *>(p1); 77 const dict_table_t *table2 = 78 (*static_cast<const fts_trx_table_t *const *>(p2))->table; 79 80 return ((*table_id > table2->id) ? 1 : (*table_id == table2->id) ? 0 : -1); 81} 82