Verified Commit 94fd5cfa authored by Camil Staps's avatar Camil Staps
Browse files

Faster type/class search with separate exact name index

parent 4469e20d
......@@ -25,6 +25,7 @@ from TypeTree import :: TypeTree
:: *CloogleDB =
{ db :: !*DB CloogleEntry AnnotationKey Annotation //* Core data
, name_ngrams :: !NGramIndex Index //* Name ngrams
, name_map :: !Map Name [Index] //* For exact name search
, types :: !TypeTree Index //* Types, map to FunctionEntries
, core :: ![Index] //* Entries in core modules
, apps :: ![Index] //* Entries in app modules
......@@ -254,6 +255,7 @@ includeBuiltins :: !*CloogleDB -> *CloogleDB
filterLibraries :: ![Name] !*CloogleDB -> *CloogleDB
filterModules :: ![Name] !*CloogleDB -> *CloogleDB
filterName :: !String !*CloogleDB -> *CloogleDB
filterExactName :: !String !*CloogleDB -> *CloogleDB
filterUnifying :: !Type !*CloogleDB -> *CloogleDB
allTypeSynonyms :: !*CloogleDB -> *(Map Name [TypeDef], *CloogleDB)
......
......@@ -228,9 +228,10 @@ classContext :: ClassEntry -> [TypeRestriction]
classContext ce = ce.ce_context
saveDB :: *CloogleDB *File -> *(*CloogleDB, *File)
saveDB wrapper=:{db,name_ngrams,types,core,apps,builtins,syntax,library_map,module_map,derive_map,instance_map} f
saveDB wrapper=:{db,name_ngrams,name_map,types,core,apps,builtins,syntax,library_map,module_map,derive_map,instance_map} f
# (db,f) = 'DB'.saveDB db f
# f = write name_ngrams f
# f = write name_map f
# f = write types f
# f = write core f
# f = write apps f
......@@ -250,6 +251,7 @@ openDB f
# ((ok,db),f) = appFst isJustU $ 'DB'.openDB f
| not ok = (Nothing, f)
# (name_ngrams,f) = read f
# (name_map,f) = read f
# (types,f) = read f
# (core,f) = read f
# (apps,f) = read f
......@@ -261,6 +263,7 @@ openDB f
# (instance_map,f) = read f
= (
name_ngrams >>= \name_ngrams ->
name_map >>= \name_map ->
types >>= \types ->
core >>= \core ->
apps >>= \apps ->
......@@ -272,6 +275,7 @@ openDB f
instance_map >>= \instance_map -> Just
{ db=fromJust db
, name_ngrams=name_ngrams
, name_map=name_map
, types=types
, core=core
, apps=apps
......@@ -406,6 +410,13 @@ where
m [c:p] [x:s] = c == x && m p s
m _ _ = False
filterExactName :: !String !*CloogleDB -> *CloogleDB
filterExactName n wrap=:{db,name_map}
# db = 'DB'.searchIndices Intersect [(i,[]) \\ i <- idxs] db
= {wrap & db=db}
where
idxs = fromMaybe [] $ get n name_map
filterUnifying :: !Type !*CloogleDB -> *CloogleDB
filterUnifying t wrap=:{db,types}
# db = 'DB'.searchIndices Intersect idxs db
......
......@@ -8,8 +8,8 @@ import CloogleDB
:: TemporaryDB
newTemporaryDb :: TemporaryDB
finaliseDb :: ![CloogleEntry] !TemporaryDB -> *CloogleDB
newTemporaryDB :: TemporaryDB
finaliseDB :: ![CloogleEntry] !TemporaryDB -> *CloogleDB
/**
* Find all modules that could be indexed
......
......@@ -105,8 +105,8 @@ from Doc import :: ModuleDoc, :: FunctionDoc{..}, :: ClassDoc, :: TypeDoc{..},
, temp_modules :: ![ModuleEntry]
}
newTemporaryDb :: TemporaryDB
newTemporaryDb
newTemporaryDB :: TemporaryDB
newTemporaryDB
= { temp_functions = []
, temp_classes = []
, temp_instances = []
......@@ -116,11 +116,15 @@ newTemporaryDb
, temp_modules = []
}
finaliseDb :: ![CloogleEntry] !TemporaryDB -> *'CDB'.CloogleDB
finaliseDb extra tdb =
finaliseDB :: ![CloogleEntry] !TemporaryDB -> *'CDB'.CloogleDB
finaliseDB extra tdb =
{ db = newDB entries
, name_ngrams = foldr (uncurry index) (newNGramIndex 3 True)
[('CDB'.getName loc, i) \\ (i,e) <- entridxs, Just loc <- ['CDB'.getLocation e]]
, name_map = foldr (\(name,i) -> flip 'M'.alter name \is -> case is of
Nothing -> Just [i]
Just is -> Just [i:is]) 'M'.newMap
[('CDB'.getName loc, i) \\ (i,e) <- entridxs, Just loc <- ['CDB'.getLocation e]]
, types = foldr (uncurry addType) zero
[(snd $ 'T'.prepare_unification False synonymmap $ 'T'.removeTypeContexts t,i)
\\ (i,FunctionEntry fe) <- entridxs, Just t <- [fe.fe_type <|> (docType =<< fe.fe_documentation)]]
......
......@@ -42,11 +42,11 @@ search {unify,name,className,typeName,modules,libraries,page,include_builtins,in
# cdb = if include_builtins includeBuiltins excludeBuiltins cdb
# cdb = case typeName of
Nothing -> cdb
Just _ -> filterDB (\ce -> ce=:(TypeDefEntry _)) cdb
Just n -> filterDB (\ce -> ce=:(TypeDefEntry _)) $ filterExactName n cdb
# cdb = case className of
Nothing -> cdb
Just _ -> filterDB (\ce -> ce=:(ClassEntry _)) cdb
# cdb = case name <|> typeName <|> className of
Just n -> filterDB (\ce -> ce=:(ClassEntry _)) $ filterExactName n cdb
# cdb = case name of
Nothing -> cdb
Just name -> filterName name cdb
# (allsyns,cdb) = allTypeSynonyms cdb
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment