diff --git a/coding/timsort/timsort.cpp b/coding/timsort/timsort.cpp index 6069d91cbf..df7027a0ea 100644 --- a/coding/timsort/timsort.cpp +++ b/coding/timsort/timsort.cpp @@ -169,7 +169,7 @@ static uint32_t timCountRunAndMakeAscending(timMergeState *aState, * and determine if it is assencing or descending. * And then start checking how long respective patterns go. */ - if ((*aCmpCb)(sArray + (aIndexLow * sWidth), + if ((*aCmpCb)(sArray + (aIndexLow * sWidth), sArray + ((aIndexLow + 1) * sWidth)) == -1) { /* @@ -183,7 +183,7 @@ static uint32_t timCountRunAndMakeAscending(timMergeState *aState, while (sIndexCur < aIndexHigh) { - if ((*aCmpCb)(sArray + ((sIndexCur - 1) * sWidth), + if ((*aCmpCb)(sArray + ((sIndexCur - 1) * sWidth), sArray + (sIndexCur * sWidth)) != 1) { /* <= */ @@ -211,7 +211,7 @@ static uint32_t timCountRunAndMakeAscending(timMergeState *aState, while (sIndexCur < aIndexHigh) { - if ((*aCmpCb)(sArray + ((sIndexCur - 1) * sWidth), + if ((*aCmpCb)(sArray + ((sIndexCur - 1) * sWidth), sArray + (sIndexCur * sWidth)) == 1) { /* > */ @@ -1062,9 +1062,9 @@ LABEL_COPY_A: /* * Merges the two runs at stack indices i and i + 1. * Run i must be the penultimate or antepenultimate run on the stack. - * IOW, i must be equal to + * IOW, i must be equal to * - * i == PendingRunCnt - 2 or + * i == PendingRunCnt - 2 or * i == PendingRuncnt - 3. */ static void timMergeAt(timMergeState *aState, uint32_t aWhere, cmpFunc *aCmpCb) diff --git a/iphone/Sloynik/Shared/AppDelegate.h b/iphone/Sloynik/Shared/AppDelegate.h index d7b9f7cab5..d9e82a8b45 100644 --- a/iphone/Sloynik/Shared/AppDelegate.h +++ b/iphone/Sloynik/Shared/AppDelegate.h @@ -1,14 +1,14 @@ #import -@class SearchVC; +@class SloynikSearchVC; @interface AppDelegate : NSObject { UIWindow * window; - SearchVC * searchVC; + SloynikSearchVC * searchVC; } @property (nonatomic, retain) UIWindow * window; -@property (nonatomic, retain) SearchVC * searchVC; +@property (nonatomic, retain) SloynikSearchVC * searchVC; @end diff --git a/iphone/Sloynik/Shared/AppDelegate.mm b/iphone/Sloynik/Shared/AppDelegate.mm index d8fc6e6930..ca22f6c790 100644 --- a/iphone/Sloynik/Shared/AppDelegate.mm +++ b/iphone/Sloynik/Shared/AppDelegate.mm @@ -1,5 +1,5 @@ #import "AppDelegate.h" -#import "SearchVC.h" +#import "SloynikSearchVC.h" #import "PerfCount.h" @implementation AppDelegate @@ -28,7 +28,7 @@ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.window.backgroundColor = [UIColor whiteColor]; - self.searchVC = [[[SearchVC alloc] init] autorelease]; + self.searchVC = [[[SloynikSearchVC alloc] init] autorelease]; [self.window addSubview:searchVC.view]; [self.window makeKeyAndVisible]; LogTimeCounter("StartTime", "applicationDidFinishLaunching_end"); diff --git a/iphone/Sloynik/Shared/ArticleVC.mm b/iphone/Sloynik/Shared/ArticleVC.mm index 166a9210a7..7aad3c3e37 100644 --- a/iphone/Sloynik/Shared/ArticleVC.mm +++ b/iphone/Sloynik/Shared/ArticleVC.mm @@ -134,7 +134,7 @@ initWithCustomView:self.backForwardButtons]; self.navArticle.rightBarButtonItem = segmentBarItem; [segmentBarItem release]; - + if ([NSClassFromString(@"UISwipeGestureRecognizer") instancesRespondToSelector:@selector(setDirection:)]) { @@ -157,7 +157,7 @@ autorelease]; self.pinchGestureRecognizer.delegate = self; } - + [self loadWebView]; UIView * mainView = [[[UIView alloc] initWithFrame:frame] autorelease]; @@ -212,7 +212,7 @@ - (void)setArticleData:(NSString *)htmlString name:(NSString *)name { // Make sure, that WebView is created. - [self view]; + [self view]; // Load data into WebView. [self.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://s/"]]; diff --git a/iphone/Sloynik/Shared/PerfCount.h b/iphone/Sloynik/Shared/PerfCount.h index fafd56f5d4..a2dbc10659 100644 --- a/iphone/Sloynik/Shared/PerfCount.h +++ b/iphone/Sloynik/Shared/PerfCount.h @@ -3,7 +3,7 @@ #if __cplusplus extern "C" { #endif - + void LogTimeCounter(const char * counter, const char * message); #if __cplusplus diff --git a/iphone/Sloynik/Shared/PerfCount.mm b/iphone/Sloynik/Shared/PerfCount.mm index b01d8602bf..b45e2a757f 100644 --- a/iphone/Sloynik/Shared/PerfCount.mm +++ b/iphone/Sloynik/Shared/PerfCount.mm @@ -18,6 +18,6 @@ void LogTimeCounter(const char * counter, const char * message) else { NSLog(@"LogTimeCounter: %s %s %f", counter, message, t - it->second); - it->second = t; + it->second = t; } } diff --git a/iphone/Sloynik/Shared/SearchVC.h b/iphone/Sloynik/Shared/SearchVC.h index e24b91588e..dfe90dbc90 100644 --- a/iphone/Sloynik/Shared/SearchVC.h +++ b/iphone/Sloynik/Shared/SearchVC.h @@ -10,18 +10,13 @@ typedef struct SloynikData SloynikData; SloynikData * m_pSloynikData; UISearchBar * searchBar; UITableView * resultsView; - UIBarButtonItem * menuButton; ArticleVC * articleVC; - CGRect initFrame; } -@property (nonatomic, retain) UISearchBar * searchBar; -@property (nonatomic, retain) UITableView * resultsView; -@property (nonatomic, retain) UIBarButtonItem * menuButton; +@property (nonatomic, retain) IBOutlet UISearchBar * searchBar; +@property (nonatomic, retain) IBOutlet UITableView * resultsView; @property (nonatomic, retain) ArticleVC * articleVC; -@property (nonatomic) CGRect initFrame; -- (void)menuButtonPressed; - (void)willShowArticle; - (void)showArticle; diff --git a/iphone/Sloynik/Shared/SearchVC.mm b/iphone/Sloynik/Shared/SearchVC.mm index 1727c2e08c..4abe70dfea 100644 --- a/iphone/Sloynik/Shared/SearchVC.mm +++ b/iphone/Sloynik/Shared/SearchVC.mm @@ -10,11 +10,11 @@ struct SloynikData { sl::SloynikEngine::SearchResult m_SearchResult; - + SloynikData() : m_SearchResult() { } - + ~SloynikData() { } @@ -24,84 +24,34 @@ struct SloynikData @synthesize searchBar; @synthesize resultsView; -@synthesize menuButton; @synthesize articleVC; -@synthesize initFrame; - (void)dealloc { delete m_pSloynikData; self.searchBar = nil; self.resultsView = nil; - self.menuButton = nil; self.articleVC = nil; [super dealloc]; } -// Implement loadView to create a view hierarchy programmatically, without using a nib. -- (void)loadView -{ - int const buttonW = 40; - int const toolbarH = 44; - int const marginW = 5; - CGRect frame = initFrame; - int const frameW = frame.size.width; - int const frameH = frame.size.height; - - CGRect searchBarFrame = CGRectMake(0, 0, frameW - buttonW - 2 * marginW, toolbarH); - CGRect navBarFrame = CGRectMake(frameW - buttonW - 2 * marginW, 0, - buttonW + 2 * marginW, toolbarH); - CGRect resultsFrame = CGRectMake(0, toolbarH, frameW, frameH - toolbarH); - - self.searchBar = [[[UISearchBar alloc] initWithFrame:searchBarFrame] autorelease]; - self.searchBar.delegate = self; - self.searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; - [self.searchBar becomeFirstResponder]; - - self.menuButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"menu-20.png"] - style:UIBarButtonItemStylePlain - target:self - action:@selector(menuButtonPressed)]; - - UINavigationItem * navItem = [[[UINavigationItem alloc] initWithTitle:@""] autorelease]; - navItem.rightBarButtonItem = self.menuButton; - - UINavigationBar * navBar = [[[UINavigationBar alloc] initWithFrame:navBarFrame] autorelease]; - navBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; - [navBar pushNavigationItem:navItem animated:NO]; - - self.resultsView = [[[UITableView alloc] initWithFrame:resultsFrame] autorelease]; - self.resultsView.rowHeight = 40; - self.resultsView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | - UIViewAutoresizingFlexibleHeight); - self.resultsView.dataSource = self; - self.resultsView.delegate = self; - self.resultsView.hidden = YES; - - UIView * mainView = [[[UIView alloc] initWithFrame:frame] autorelease]; - [mainView addSubview:self.searchBar]; - [mainView addSubview:navBar]; - [mainView addSubview:self.resultsView]; - self.view = mainView; -} - // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; + + self.searchBar.delegate = self; + + self.resultsView.dataSource = self; + self.resultsView.delegate = self; + self.resultsView.hidden = YES; + LogTimeCounter("StartTime", "SearchVC initializing."); m_pSloynikData = new SloynikData; GetSloynikEngine()->Search("", m_pSloynikData->m_SearchResult); LogTimeCounter("StartTime", "SearchVC initialized."); } -// Override to allow orientations other than the default portrait orientation. -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation -{ - // Return YES for supported orientations - return YES; -} - - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. @@ -233,8 +183,4 @@ struct SloynikData [[superView layer] addAnimation:animation forKey:@"SwitchToArticleView"]; } -- (void)menuButtonPressed -{ -} - @end diff --git a/iphone/Sloynik/Shared/global.mm b/iphone/Sloynik/Shared/global.mm index deb9eac01b..550343da87 100644 --- a/iphone/Sloynik/Shared/global.mm +++ b/iphone/Sloynik/Shared/global.mm @@ -71,5 +71,5 @@ sl::SloynikEngine * GetSloynikEngine() s_pEngine = new sl::SloynikEngine(dictionaryPath, indexPath, strFn); LogTimeCounter("EngineStartUp", "Engine started."); } - return s_pEngine; + return s_pEngine; } diff --git a/iphone/Sloynik/Shared/main.m b/iphone/Sloynik/Shared/main.m index 22451fd27b..a1ff6ee209 100644 --- a/iphone/Sloynik/Shared/main.m +++ b/iphone/Sloynik/Shared/main.m @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) { - LogTimeCounter("StartTime", "main"); + LogTimeCounter("StartTime", "main"); NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate"); diff --git a/iphone/Sloynik/Sloynik.xcodeproj/project.pbxproj b/iphone/Sloynik/Sloynik.xcodeproj/project.pbxproj index d379b152f7..7480f86ffb 100755 --- a/iphone/Sloynik/Sloynik.xcodeproj/project.pbxproj +++ b/iphone/Sloynik/Sloynik.xcodeproj/project.pbxproj @@ -35,6 +35,7 @@ 49698404121E877E00048CF1 /* huffman.c in Sources */ = {isa = PBXBuildFile; fileRef = 496983FF121E877E00048CF1 /* huffman.c */; }; 49698405121E877E00048CF1 /* randtable.c in Sources */ = {isa = PBXBuildFile; fileRef = 49698400121E877E00048CF1 /* randtable.c */; }; 4972C89B120CB8D5001F025D /* menu-20.png in Resources */ = {isa = PBXBuildFile; fileRef = 4972C89A120CB8D5001F025D /* menu-20.png */; }; + 4983ADC8134618AE00C82DB7 /* SloynikSearchVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 4983ADC7134618AE00C82DB7 /* SloynikSearchVC.m */; }; 499A290F120CDF4000E14B47 /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499A290E120CDF4000E14B47 /* AppDelegate.mm */; }; 499F013212344F3C00EB6964 /* ArticleVC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499F013112344F3C00EB6964 /* ArticleVC.mm */; }; 49A67547132EE7C2005189E6 /* timsort.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49A67546132EE7C2005189E6 /* timsort.cpp */; }; @@ -79,6 +80,8 @@ 496983FF121E877E00048CF1 /* huffman.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = huffman.c; path = ../../3party/bzip2/huffman.c; sourceTree = SOURCE_ROOT; }; 49698400121E877E00048CF1 /* randtable.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = randtable.c; path = ../../3party/bzip2/randtable.c; sourceTree = SOURCE_ROOT; }; 4972C89A120CB8D5001F025D /* menu-20.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "menu-20.png"; path = "Images/menu-20.png"; sourceTree = ""; }; + 4983ADC6134618AE00C82DB7 /* SloynikSearchVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SloynikSearchVC.h; sourceTree = ""; }; + 4983ADC7134618AE00C82DB7 /* SloynikSearchVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SloynikSearchVC.m; sourceTree = ""; }; 499A290D120CDF4000E14B47 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = Shared/AppDelegate.h; sourceTree = ""; }; 499A290E120CDF4000E14B47 /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = Shared/AppDelegate.mm; sourceTree = ""; }; 499F013012344F3C00EB6964 /* ArticleVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ArticleVC.h; path = Shared/ArticleVC.h; sourceTree = ""; }; @@ -122,6 +125,8 @@ 499A290E120CDF4000E14B47 /* AppDelegate.mm */, 496982CF121DE3F700048CF1 /* SearchVC.h */, 496982D0121DE3F700048CF1 /* SearchVC.mm */, + 4983ADC6134618AE00C82DB7 /* SloynikSearchVC.h */, + 4983ADC7134618AE00C82DB7 /* SloynikSearchVC.m */, 499F013012344F3C00EB6964 /* ArticleVC.h */, 499F013112344F3C00EB6964 /* ArticleVC.mm */, 491F5E5512E8F4650072775A /* global.hpp */, @@ -339,6 +344,7 @@ 499F013212344F3C00EB6964 /* ArticleVC.mm in Sources */, 491F5E5712E8F4AB0072775A /* global.mm in Sources */, 49A67547132EE7C2005189E6 /* timsort.cpp in Sources */, + 4983ADC8134618AE00C82DB7 /* SloynikSearchVC.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/iphone/Sloynik/SloynikSearchVC.h b/iphone/Sloynik/SloynikSearchVC.h new file mode 100644 index 0000000000..3c14611713 --- /dev/null +++ b/iphone/Sloynik/SloynikSearchVC.h @@ -0,0 +1,21 @@ +// +// SloynikSearchVC.h +// Sloynik +// +// Created by Yury Melnichek on 01.04.11. +// Copyright 2011 -. All rights reserved. +// + +#import +#import "SearchVC.h" + +@interface SloynikSearchVC : SearchVC +{ + UIBarButtonItem * menuButton; +} + +@property (nonatomic, retain) UIBarButtonItem * menuButton; + +- (void)menuButtonPressed; + +@end diff --git a/iphone/Sloynik/SloynikSearchVC.m b/iphone/Sloynik/SloynikSearchVC.m new file mode 100644 index 0000000000..29750bc65a --- /dev/null +++ b/iphone/Sloynik/SloynikSearchVC.m @@ -0,0 +1,109 @@ +// +// SloynikSearchVC.m +// Sloynik +// +// Created by Yury Melnichek on 01.04.11. +// Copyright 2011 -. All rights reserved. +// + +#import "SloynikSearchVC.h" + + +@implementation SloynikSearchVC + +@synthesize menuButton; + + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + } + return self; +} + +- (void)dealloc +{ + [super dealloc]; + self.menuButton = nil; +} + +- (void)didReceiveMemoryWarning +{ + // Releases the view if it doesn't have a superview. + [super didReceiveMemoryWarning]; + + // Release any cached data, images, etc that aren't in use. +} + +// Implement loadView to create a view hierarchy programmatically, without using a nib. +- (void)loadView +{ + int const buttonW = 40; + int const toolbarH = 44; + int const marginW = 5; + CGRect frame = [[UIScreen mainScreen] applicationFrame]; + int const frameW = frame.size.width; + int const frameH = frame.size.height; + + CGRect searchBarFrame = CGRectMake(0, 0, frameW - buttonW - 2 * marginW, toolbarH); + CGRect navBarFrame = CGRectMake(frameW - buttonW - 2 * marginW, 0, + buttonW + 2 * marginW, toolbarH); + CGRect resultsFrame = CGRectMake(0, toolbarH, frameW, frameH - toolbarH); + + self.searchBar = [[[UISearchBar alloc] initWithFrame:searchBarFrame] autorelease]; + self.searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; + [self.searchBar becomeFirstResponder]; + + self.menuButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"menu-20.png"] + style:UIBarButtonItemStylePlain + target:self + action:@selector(menuButtonPressed)]; + + UINavigationItem * navItem = [[[UINavigationItem alloc] initWithTitle:@""] autorelease]; + navItem.rightBarButtonItem = self.menuButton; + + UINavigationBar * navBar = [[[UINavigationBar alloc] initWithFrame:navBarFrame] autorelease]; + navBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; + [navBar pushNavigationItem:navItem animated:NO]; + + self.resultsView = [[[UITableView alloc] initWithFrame:resultsFrame] autorelease]; + self.resultsView.rowHeight = 40; + self.resultsView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | + UIViewAutoresizingFlexibleHeight); + + UIView * mainView = [[[UIView alloc] initWithFrame:frame] autorelease]; + [mainView addSubview:self.searchBar]; + [mainView addSubview:navBar]; + [mainView addSubview:self.resultsView]; + self.view = mainView; +} + +/* +// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. +- (void)viewDidLoad +{ + [super viewDidLoad]; +} +*/ + +- (void)viewDidUnload +{ + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + +// Override to allow orientations other than the default portrait orientation. +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + // Return YES for supported orientations + return YES; +} + +- (void)menuButtonPressed +{ +} + +@end