Note that there are some explanatory texts on larger screens.

plurals
  1. POIOS word game. Validate word performance
    primarykey
    data
    text
    <p>I'm building a scrabble game, and having some problem with the word dictionary. It contains ~700,000 words, and about 18 MB big. </p> <p>Right now, I'm loading the whole dict into an array, which takes 12 seconds on an iPhone 4. </p> <pre><code>wordList = [NSMutableArray arrayWithContentsOfFile: [[self applicationDocumentsDirectory] stringByAppendingString:@"/wordlist.plist"]]; </code></pre> <p>I have two questions: </p> <ol> <li><p>Is there a better way to load the wordlist faster and/or reduce memory? </p></li> <li><p>It takes about 12 seconds to get all possible words from a set of letters. Is it possible to make it quicker? Here's the code: </p> <pre><code>-(NSMutableArray *)getValidWords:(NSString *)letters{ NSMutableArray *list = [[NSMutableArray alloc] init]; for (int i = 0, c = [wordList count]; i &lt; c; i++){ if ([self isWordValid: [wordList objectAtIndex: i] forLetters:letters]){ [list addObject:[wordList objectAtIndex: i]]; } } return list; </code></pre> <p>}</p> <pre><code>- (BOOL)isWordValid:(NSString *)word forLetters:(NSString *)ltrs{ int i, z; NSRange range; BOOL found; static NSMutableString *letters = nil; if ([word length] &lt; 2) return NO; if(letters == nil) { letters = [[NSMutableString alloc] initWithString:ltrs]; } else { [letters setString: ltrs]; } found = NO; range.length = 1; for(i = 0; i &lt; [word length]; i++){ for(z = 0; z &lt; [letters length]; z++){ if([word characterAtIndex:i] == [letters characterAtIndex:z]){ range.location = z; [letters deleteCharactersInRange: range]; found = YES; break; } } if (found == NO){ return NO; } found = NO; } return YES; } </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload