Ejemplo n.º 1
0
 void advanceInput()
 {
   RecognizerSharedStateType *state = get_state();
   state->set_tokenStartCharIndex(getCharIndex());    
   state->set_tokenStartCharPositionInLine(getCharPositionInLine());
   state->set_tokenStartLine(getLine());
 }
Ejemplo n.º 2
0
Archivo: board.c Proyecto: Glank/chess
ChessPiece* __newPieceFromChar(char c, location_t loc){
    int typeColor = getCharIndex(c, "KkQqRrNnBbPp", 12);
    if(typeColor==-1)
        printf("%c\n", c);
    assert(typeColor!=-1);
    pieceType_e type = (pieceType_e)(typeColor&(~1));
    color_e color = (color_e)(typeColor&1);
    return ChessPiece_new(color, type, loc);
}
bool isPermutationOfPallindrome3( const std::string & str )
{
    int bitVector = 0;
    int id = 0;
    for ( const char & c : str )
    {
        id = getCharIndex(c);
        bitVector = toggle (bitVector, id );
    }
    return ( bitVector == 0 || isExactlyOneBitSet(bitVector) );
}
void countFrequency( const std::string & str, int *frequency )
{
    int idx;
    for (const char & c : str)
    {
        idx = getCharIndex(c);
        if ( idx != -1 )
        {
            ++frequency[idx];
        }
    }
}
bool isPermutationOfPallindrome2( const std::string & str )
{
    int oddCount = 0;
    int frequency[26] = { 0 };
    int idx = 0;
    for ( const char & c : str )
    {
        idx = getCharIndex(c);
        if ( idx != -1 )
        {
            ++frequency[idx];
            if ( frequency[idx] % 2 ) 
            {   
                ++oddCount;
            } else {
                --oddCount;
            }
        }
    }
    return (oddCount <= 1);
}
Ejemplo n.º 6
0
/* begin code for insert_into_table ------------------------------------------------------------------------------------------------------------
 The insert_into_table function adds a given word to the tables that should contain it. It does this by allocating tables up to Total_Tables and adding the word to the completions list to them if there is space available. If there is no space available, the function updates TotalWords. There is no return value.
 */
void insert_into_table(const char *word){
    size_t stringLength = strlen(word);//calculate the length of the string using strlen
    int i;//number of the iteration
    Table *pointer = &Root; // pointer to the root of the table
    int index;//the index position that the character will take
    
    for (i = 0; i<Total_Tables && i<stringLength; i++){//the first iteration (i = 0) will point to the root table.
        index = getCharIndex(word[i]);//get the index that the character should go into in the table
        if (index < 0) {//the function getCharIndex will return -1 if the character doesn't fit any index.
#if DEBUG
            printf("Encountered a character, (%c), that cannot be indexed.\n", (char)word[i]);
#endif
            //index = 'z';
            continue;//don't handle the character if it cannot be indexed
        }
        
        if (pointer->nextLevel[index] == NULL){//check to make sure there is not a next level table
            pointer->nextLevel[index] = (struct table*) malloc(sizeof(struct table));//allocate space for the new table
            updateMemory(sizeof(struct table));//add to the total program overhead because of the addition of this table
            *pointer->nextLevel[index] = (struct table){{NULL},{NULL},0};//set the whole table to null values that will be filled in later
        }