third_party/cairo/src/cairo-lzw.c
static cairo_bool_t
_lzw_symbol_table_lookup (lzw_symbol_table_t	 *table,
			  lzw_symbol_t		  symbol,
			  lzw_symbol_t		**slot_ret)
{
    /* The algorithm here is identical to that in cairo-hash.c. We
     * copy it here to allow for a rather more efficient
     * implementation due to several circumstances that do not apply
     * to the more general case:
     *
     * 1) We have a known bound on the total number of symbols, so we
     *    have a fixed-size table without any copying when growing
     *
     * 2) We never delete any entries, so we don't need to
     *    support/check for DEAD entries during lookup.
     *
     * 3) The object fits in 32 bits so we store each object in its
     *    entirety within the table rather than storing objects
     *    externally and putting pointers in the table, (which here
     *    would just double the storage requirements and have negative
     *    impacts on memory locality).
     */
    int i, idx, step, hash = symbol & LZW_SYMBOL_KEY_MASK;
    lzw_symbol_t candidate;

    idx = hash % LZW_SYMBOL_MOD1;
    step = 0;

    *slot_ret = NULL;
    for (i = 0; i < LZW_SYMBOL_TABLE_SIZE; i++)
    {
	candidate = table->table[idx];
	if (candidate == LZW_SYMBOL_FREE)
	{
	    *slot_ret = &table->table[idx];
	    return FALSE;
	}
	else /* candidate is LIVE */
	{
	    if ((candidate & LZW_SYMBOL_KEY_MASK) ==
		(symbol & LZW_SYMBOL_KEY_MASK))
	    {
		*slot_ret = &table->table[idx];
		return TRUE;
	    }
	}

	if (step == 0) {
	    step = hash % LZW_SYMBOL_MOD2;
	    if (step == 0)
		step = 1;
	}

	idx += step;
	if (idx >= LZW_SYMBOL_TABLE_SIZE)
	    idx -= LZW_SYMBOL_TABLE_SIZE;
    }

    return FALSE;
}
/* Lookup a symbol in the symbol table. The PREV and NEXT fields of
 * symbol form the key for the lookup.
 *
 * If successful, then this function returns %TRUE and slot_ret will be
 * left pointing at the result that will have the CODE field of
 * interest.
 *
 * If the lookup fails, then this function returns %FALSE and slot_ret
 * will be pointing at the location in the table to which a new CODE
 * value should be stored along with PREV and NEXT.
 */
Lookup a symbol in the symbol table. The PREV and NEXT fields of
symbol form the key for the lookup.

If successful, then this function returns %TRUE and slot_ret will be
left pointing at the result that will have the CODE field of
interest.

If the lookup fails, then this function returns %FALSE and slot_ret
will be pointing at the location in the table to which a new CODE
value should be stored along with PREV and NEXT.
Lookup a symbol in the symbol table . The PREV and NEXT fields of symbol form the key for the lookup . If successful then this function returns %TRUE and slot_ret will be left pointing at the result that will have the CODE field of interest . If the lookup fails then this function returns %FALSE and slot_ret will be pointing at the location in the table to which a new CODE value should be stored along with PREV and NEXT .
static cairo_bool_t
_lzw_symbol_table_lookup (lzw_symbol_table_t	 *table,
			  lzw_symbol_t		  symbol,
			  lzw_symbol_t		**slot_ret)
{
    int i, idx, step, hash = symbol & LZW_SYMBOL_KEY_MASK;
    lzw_symbol_t candidate;
    idx = hash % LZW_SYMBOL_MOD1;
    step = 0;
    *slot_ret = NULL;
    for (i = 0; i < LZW_SYMBOL_TABLE_SIZE; i++)
    {
	candidate = table->table[idx];
	if (candidate == LZW_SYMBOL_FREE)
	{
	    *slot_ret = &table->table[idx];
	    return FALSE;
	}
	else 
	{
	    if ((candidate & LZW_SYMBOL_KEY_MASK) ==
		(symbol & LZW_SYMBOL_KEY_MASK))
	    {
		*slot_ret = &table->table[idx];
		return TRUE;
	    }
	}
	if (step == 0) {
	    step = hash % LZW_SYMBOL_MOD2;
	    if (step == 0)
		step = 1;
	}
	idx += step;
	if (idx >= LZW_SYMBOL_TABLE_SIZE)
	    idx -= LZW_SYMBOL_TABLE_SIZE;
    }
    return FALSE;
}
static cairo_bool_t _lzw_symbol_table_lookup ( lzw_symbol_table_t * table , lzw_symbol_t symbol , lzw_symbol_t * * slot_ret ) { int i , idx , step , hash = symbol & LZW_SYMBOL_KEY_MASK ; lzw_symbol_t candidate ; idx = hash % LZW_SYMBOL_MOD1 ; step = 0 ; * slot_ret = NULL ; for ( i = 0 ; i < LZW_SYMBOL_TABLE_SIZE ; i ++ ) { candidate = table -> table [ idx ] ; if ( candidate == LZW_SYMBOL_FREE ) { * slot_ret = & table -> table [ idx ] ; return FALSE ; } else { if ( ( candidate & LZW_SYMBOL_KEY_MASK ) == ( symbol & LZW_SYMBOL_KEY_MASK ) ) { * slot_ret = & table -> table [ idx ] ; return TRUE ; } } if ( step == 0 ) { step = hash % LZW_SYMBOL_MOD2 ; if ( step == 0 ) step = 1 ; } idx += step ; if ( idx >= LZW_SYMBOL_TABLE_SIZE ) idx -= LZW_SYMBOL_TABLE_SIZE ; } return FALSE ; }
Lookup a symbol in the symbol table.
Lookup a symbol in the symbol table .
/* The algorithm here is identical to that in cairo-hash.c. We
     * copy it here to allow for a rather more efficient
     * implementation due to several circumstances that do not apply
     * to the more general case:
     *
     * 1) We have a known bound on the total number of symbols, so we
     *    have a fixed-size table without any copying when growing
     *
     * 2) We never delete any entries, so we don't need to
     *    support/check for DEAD entries during lookup.
     *
     * 3) The object fits in 32 bits so we store each object in its
     *    entirety within the table rather than storing objects
     *    externally and putting pointers in the table, (which here
     *    would just double the storage requirements and have negative
     *    impacts on memory locality).
     */ /* candidate is LIVE */