Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eecs398-search
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vcday
eecs398-search
Commits
6415adf0
Commit
6415adf0
authored
7 years ago
by
Nicholas Yang
Browse files
Options
Downloads
Patches
Plain Diff
code cleanup
parent
b4f7eadf
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
indexer/Indexer.cpp
+15
-19
15 additions, 19 deletions
indexer/Indexer.cpp
indexer/Indexer.h
+0
-2
0 additions, 2 deletions
indexer/Indexer.h
with
15 additions
and
21 deletions
indexer/Indexer.cpp
+
15
−
19
View file @
6415adf0
#include
"Indexer.h"
Indexer
::
Indexer
()
{
indexedCount
=
0
;
currentFile
=
0
;
totalIndexed
=
0
;
currentlyIndexed
=
0
;
currentBlockNumberWords
=
0
;
...
...
@@ -14,29 +12,34 @@ void Indexer::run() {
while
(
pointerToDictionaries
.
Size
()
!=
0
)
{
unordered_map
<
string
,
vector
<
int
>
>*
dictionary
=
pointerToDictionaries
.
Pop
();
DocumentEnding
docEnd
=
DocumentEnding
();
size_t
indexedCount
=
0
;
currentBlockNumberDocs
++
;
for
(
auto
word
:
*
dictionary
)
{
if
(
word
.
first
.
at
(
0
)
==
'='
)
{
docEnd
.
url
=
word
.
first
.
substr
(
1
,
word
.
first
.
length
());
continue
;
}
indexedCount
+=
word
.
second
.
size
();
totalIndexed
+=
word
.
second
.
size
();
currentBlockNumberWords
+=
word
.
second
.
size
();
for
(
auto
location
:
word
.
second
)
{
masterDictionary
[
word
.
first
].
push_back
(
currentlyIndexed
+
location
);
}
}
currentlyIndexed
+=
indexedCount
;
docEnd
.
docEndPosition
=
currentlyIndexed
;
docEnd
.
docNumWords
=
indexedCount
;
docEndings
.
push_back
(
docEnd
);
if
(
currentBlockNumberWords
>=
300000
)
{
save
();
reset
();
}
indexedCount
=
0
;
}
save
();
reset
();
}
...
...
@@ -46,7 +49,7 @@ void Indexer::verbose_run() {
unordered_map
<
string
,
vector
<
int
>>
dictionary
=
*
pointerToDictionaries
.
Pop
();
for
(
auto
word
:
dictionary
)
{
for
(
auto
location
:
word
.
second
)
{
indexedCount
++
;
//
indexedCount++;
masterDictionary
[
word
.
first
].
push_back
(
location
);
}
}
...
...
@@ -58,6 +61,7 @@ void Indexer::save() {
map
<
string
,
size_t
>
seeker
;
string
fileName
=
"index"
+
to_string
(
currentFile
)
+
".txt"
;
int
file
=
open
(
fileName
.
c_str
(),
O_CREAT
|
O_WRONLY
,
S_IRWXU
);
// TODO: these should really be c strings
string
header
=
"===STATS===
\n
"
;
string
uniqueWords
=
"unique words: "
+
to_string
(
masterDictionary
.
size
())
+
"
\n
"
;
...
...
@@ -69,34 +73,27 @@ void Indexer::save() {
write
(
file
,
numberWords
.
c_str
(),
strlen
(
numberWords
.
c_str
()));
write
(
file
,
numberDocs
.
c_str
(),
strlen
(
numberDocs
.
c_str
()));
write
(
file
,
footer
.
c_str
(),
strlen
(
footer
.
c_str
()));
// REALLY GROSS HACK
in
t
seekOffset
=
strlen
(
header
.
c_str
())
+
size_
t
seekOffset
=
strlen
(
header
.
c_str
())
+
strlen
(
numberDocs
.
c_str
())
+
strlen
(
numberWords
.
c_str
())
+
strlen
(
uniqueWords
.
c_str
())
+
strlen
(
footer
.
c_str
());
bool
first
=
true
;
for
(
auto
word
:
maps
)
{
if
(
first
)
{
//REALLY BAD HACKK
first
=
false
;
seeker
[
word
.
first
]
=
seekOffset
;
}
else
{
seeker
[
word
.
first
]
=
seekOffset
;
}
seeker
[
word
.
first
]
=
seekOffset
;
// string wordBreak = word.first + "\n";
// write(file, wordBreak.c_str(), strlen(wordBreak.c_str()));
// seekOffset += strlen(wordBreak.c_str());
bool
first
=
true
;
bool
first
Post
=
true
;
size_t
lastOne
=
0
;
for
(
auto
location
:
word
.
second
)
{
if
(
first
)
{
if
(
first
Post
)
{
string
locationSpace
=
to_string
(
location
)
+
" "
;
write
(
file
,
locationSpace
.
c_str
(),
strlen
(
locationSpace
.
c_str
()));
seekOffset
+=
strlen
(
locationSpace
.
c_str
());
first
=
false
;
first
Post
=
false
;
}
else
{
size_t
delta
=
location
-
lastOne
;
string
deltaSpace
=
to_string
(
delta
)
+
" "
;
...
...
@@ -146,7 +143,6 @@ void Indexer::verbose_save() {
void
Indexer
::
reset
()
{
masterDictionary
.
clear
();
docEndings
.
clear
();
currentBlockNumberWords
=
0
;
...
...
This diff is collapsed.
Click to expand it.
indexer/Indexer.h
+
0
−
2
View file @
6415adf0
...
...
@@ -42,9 +42,7 @@ class Indexer {
vector
<
DocumentEnding
>
docEndings
;
size_t
indexedCount
;
size_t
currentFile
;
size_t
totalIndexed
;
size_t
currentlyIndexed
;
size_t
currentBlockNumberWords
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment