⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phb_name_num_index.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 5 页
字号:
        result->distance = -1;
    }

    /* (first->tel_num == 
       external_data->table[second_pos->position].tel_num) */
    else
    {
        if (first->signature > external_data->table[second_pos->position].tel_num_sig)
        {
            result->distance = 1;
        }
        else if (first->signature < external_data->table[second_pos->position].tel_num_sig)
        {
            result->distance = -1;
        }

        /* (first->signature == external_data->table[second_pos->position].tel_num_sig) */
        else
        {
            result->distance = 0;
        }
    }
}   /* end of phb_compare_by_tel_num_sig */


/*****************************************************************************
 * FUNCTION
 *  phb_compare_by_alpha_id_for_sort
 * DESCRIPTION
 *  Compare two alpha_id's. Their length could be unequal when comparing.
 *  For ASCII charset, character comparison is case insensitive.
 * PARAMETERS
 *  external_data       [IN]        External data
 *  first_pos           [?]         
 *  second_pos          [?]         
 *  result              [?]         
 *  first(?)
 *  second(?)
 * RETURNS
 *  void
 *****************************************************************************/
#if defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__)
void phb_compare_by_alpha_id_for_sort(
        data_entry_table_type *external_data,
        pindex_struct *first_pos,
        pindex_struct *second_pos,
        compare_result_type *result)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    istring_type istr_first, istr_second;

    /* MTK 2003-12-30 Wilson, For PinYin Sort. */
    kal_uint8 temp1[PHB_ALPHA_ID_DEPTH], temp2[PHB_ALPHA_ID_DEPTH];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_COMPARE_BY_ALPHA_ID_FOR_SORT);

    /* if charset == PHB_UCS2,  && first byte range is Chinese, go lookup table 
       for subsititue string for compare */
    /* MTK 2003-12-30 Wilson, For PinYin Sort. */
    if ((external_data->table[first_pos->position].alpha_id.charset == PHB_UCS2) &&
        (find_pinyin_str_for_ucs2_with_tone(external_data->table[first_pos->position].alpha_id.data, temp1)))
    {
        istr_first.data = temp1;
        istr_first.length = strlen((char*)istr_first.data);
        istr_first.charset = PHB_ASCII;
    }
    else
    {
        istr_first.length = external_data->table[first_pos->position].alpha_id.length;
        istr_first.charset = external_data->table[first_pos->position].alpha_id.charset;
        istr_first.data = external_data->table[first_pos->position].alpha_id.data;
    }

    /* MTK 2003-12-30 Wilson, For PinYin Sort. */
    if ((external_data->table[second_pos->position].alpha_id.charset == PHB_UCS2) &&
        (find_pinyin_str_for_ucs2_with_tone(external_data->table[second_pos->position].alpha_id.data, temp2)))
    {
        istr_second.data = temp2;
        istr_second.length = strlen((char*)istr_second.data);
        istr_second.charset = PHB_ASCII;
    }
    else
    {
        istr_second.length = external_data->table[second_pos->position].alpha_id.length;
        istr_second.charset = external_data->table[second_pos->position].alpha_id.charset;
        istr_second.data = external_data->table[second_pos->position].alpha_id.data;
    }

    phb_istring_icmp(&istr_first, &istr_second, result);
}   /* end of phb_compare_by_alpha_id */
#else /* defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__) */ 


/*****************************************************************************
 * FUNCTION
 *  phb_compare_by_alpha_id_for_sort
 * DESCRIPTION
 *  
 * PARAMETERS
 *  external_data       [?]     
 *  first_pos           [?]     
 *  second_pos          [?]     
 *  result              [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void phb_compare_by_alpha_id_for_sort(
        data_entry_table_type *external_data,
        pindex_struct *first_pos,
        pindex_struct *second_pos,
        compare_result_type *result)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    istring_type istr_first, istr_second;
    kal_uint16 code;
    kal_uint8 *temp;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_COMPARE_BY_ALPHA_ID_FOR_SORT);

    /* if charset == PHB_UCS2,  && first byte range is Chinese, go lookup table 
       for subsititue string for compare */
    code = *((kal_uint16*) external_data->table[first_pos->position].alpha_id.data);
    if ((external_data->table[first_pos->position].alpha_id.charset == PHB_UCS2)
        && (code >= 0x4e00 && code <= 0x9fa5) && ((temp = (kal_uint8*) find_pinying_str_for_ucs2(code)) != NULL))
    {
        istr_first.data = temp;
        istr_first.length = strlen((char*)istr_first.data);
        istr_first.charset = PHB_ASCII;
    }
    else
    {
        istr_first.length = external_data->table[first_pos->position].alpha_id.length;
        istr_first.charset = external_data->table[first_pos->position].alpha_id.charset;
        istr_first.data = external_data->table[first_pos->position].alpha_id.data;
    }

    code = *((kal_uint16*) external_data->table[second_pos->position].alpha_id.data);
    if ((external_data->table[second_pos->position].alpha_id.charset == PHB_UCS2)
        && (code >= 0x4e00 && code <= 0x9fa5) && ((temp = (kal_uint8*) find_pinying_str_for_ucs2(code)) != NULL))
    {
        istr_second.data = temp;
        istr_second.length = strlen((char*)istr_second.data);
        istr_second.charset = PHB_ASCII;
    }
    else
    {
        istr_second.length = external_data->table[second_pos->position].alpha_id.length;
        istr_second.charset = external_data->table[second_pos->position].alpha_id.charset;
        istr_second.data = external_data->table[second_pos->position].alpha_id.data;
    }

    phb_istring_icmp(&istr_first, &istr_second, result);
}   /* end of phb_compare_by_alpha_id */
#endif /* defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__) */ 


/*****************************************************************************
 * FUNCTION
 *  phb_compare_by_alpha_id_storage_for_sort
 * DESCRIPTION
 *  Compare two alpha_id and storage's.
 *  Inequality definition: SIM is larger than NVRAM.
 * PARAMETERS
 *  external_data       [IN]        External data
 *  first_pos           [?]         
 *  second_pos          [?]         
 *  result              [?]         
 *  first(?)
 *  second(?)
 * RETURNS
 *  void
 *****************************************************************************/
#if defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__)    /* MTK 2004-04-19 Wilson */
extern alpha_id_type alpha_id_pinyin_PHB[];
#endif 

static void phb_compare_by_alpha_id_storage_for_sort(
                data_entry_table_type *external_data,
                pindex_struct *first_pos,
                pindex_struct *second_pos,
                compare_result_type *result)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_COMPARE_BY_ALPHA_ID_STORAGE_FOR_SORT);

    phb_compare_by_alpha_id_for_sort(external_data, first_pos, second_pos, result);

    /* MTK 2004-04-19 Wilson, Put ASCII string in front of UCS2 string.(For PinYin Search) */
#if defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__)
    if (result->distance == 0)
    {
        /* If Original String is ASCII, appears before UCS2. For PinYin conversion only. */
        if (alpha_id_pinyin_PHB[first_pos->position].charset != alpha_id_pinyin_PHB[second_pos->position].charset)
        {
            if (alpha_id_pinyin_PHB[first_pos->position].charset == PHB_UCS2)
            {
                result->distance = 1;
            }
            else
            {
                result->distance = -1;
            }
        }
    }
#endif /* defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__) */ 
    /* Only when 2 alpha_id's are identical should their storage's are required to compare */
    if (result->distance == 0)
    {
        if (external_data->table[first_pos->position].storage != external_data->table[second_pos->position].storage)
        {
         /**
          * Define SIM is lexicongraphically larger than NVRAM.
          * Hence, if 2 alpha id's are identical, NVRAM appears in front
          * of SIM
          */
            if (external_data->table[first_pos->position].storage == PHB_SIM)
            {
                result->distance = 1;
            }
            else
            {
                result->distance = -1;
            }
        }
    }
}


/*****************************************************************************
 * FUNCTION
 *  phb_compare_by_tel_num_sig_for_sort
 * DESCRIPTION
 *  Compare two 2-digits telephone numbers. If they are equal, compare
 *  signature.
 * PARAMETERS
 *  external_data       [IN]        External data
 *  first_pos           [?]         
 *  second_pos          [?]         
 *  result              [?]         
 *  first(?)
 *  second(?)
 * RETURNS
 *  result->distance is greater than, equal to, or less than 0, according to(?)
 *  first is greater than, equal to, or less than second.(?)
 *****************************************************************************/
void phb_compare_by_tel_num_sig_for_sort(
        data_entry_table_type *external_data,
        pindex_struct *first_pos,
        pindex_struct *second_pos,
        compare_result_type *result)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_COMPARE_BY_TEL_NUM_SIG_FOR_SORT);

    result->same_count = 0;
    result->distance = 0;

    if (external_data->table[first_pos->position].tel_num > external_data->table[second_pos->position].tel_num)
    {
        result->distance = 1;
    }
    else if (external_data->table[first_pos->position].tel_num < external_data->table[second_pos->position].tel_num)
    {
        result->distance = -1;
    }

    /* (external_data->table[first_pos->position].tel_num == 
       external_data->table[second_pos->position].tel_num) */
    else
    {
        if (external_data->table[first_pos->position].tel_num_sig >
            external_data->table[second_pos->position].tel_num_sig)
        {
            result->distance = 1;
        }
        else if (external_data->table[first_pos->position].tel_num_sig <
                 external_data->table[second_pos->position].tel_num_sig)
        {
            result->distance = -1;
        }

        /* (external_data->table[second_pos->position].tel_num_sig == external_data->table[second_pos->position].tel_num_sig) */
        else
        {
            result->distance = 0;
        }
    }
}   /* end of phb_compare_by_tel_num_sig */


/*****************************************************************************
 * FUNCTION
 *  phb_binary_search
 * DESCRIPTION
 *  A generic binary search function that retrieves the index from primary index
 *  
 *  Note:
 *  Since the array to be searched does not stores unique keys,
 *  nearest algorithm is ALWAYS applied!!
 * PARAMETERS
 *  a                       [?]         
 *  external_data           [?]         
 *  length                  [IN]        
 *  low                     [IN]        
 *  high                    [IN]        
 *  key                     [?]         
 *  compare                 [IN]        
 *  name_num_index(?)       [IN]        The name_num_index
 * RETURNS
 *  KAL_TRUE if success, KAL_FALSE else.
 *****************************************************************************/
static kal_uint16 phb_binary_search(
                    pindex_struct *a,
                    data_entry_table_type *external_data,
                    kal_uint16 length,
                    int low,
                    int high,
                    void *key,
                    compare_func_type compare)
{
    /*-------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -