Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
keyboard
LatinIME
Commits
56f35a10
Commit
56f35a10
authored
11 years ago
by
Kurt Partridge
Committed by
Android (Google) Code Review
11 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Fix bug in counting words between samples"
parents
550824c7
bf62dc94
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
java/src/com/android/inputmethod/research/FixedLogBuffer.java
+17
-9
17 additions, 9 deletions
.../src/com/android/inputmethod/research/FixedLogBuffer.java
java/src/com/android/inputmethod/research/MainLogBuffer.java
+6
-11
6 additions, 11 deletions
java/src/com/android/inputmethod/research/MainLogBuffer.java
with
23 additions
and
20 deletions
java/src/com/android/inputmethod/research/FixedLogBuffer.java
+
17
−
9
View file @
56f35a10
...
...
@@ -51,10 +51,6 @@ public class FixedLogBuffer extends LogBuffer {
mNumActualWords
=
0
;
}
protected
int
getNumActualWords
()
{
return
mNumActualWords
;
}
/**
* Adds a new LogUnit to the front of the LIFO queue, evicting existing LogUnit's
* (oldest first) if word capacity is reached.
...
...
@@ -119,12 +115,24 @@ public class FixedLogBuffer extends LogBuffer {
return
logUnit
;
}
protected
void
shiftOutWords
(
final
int
numWords
)
{
final
int
targetNumWords
=
mNumActualWords
-
numWords
;
final
LinkedList
<
LogUnit
>
logUnits
=
getLogUnits
();
while
(
mNumActualWords
>
targetNumWords
&&
!
logUnits
.
isEmpty
())
{
shiftOut
();
/**
* Remove LogUnits from the front of the LogBuffer until {@code numWords} have been removed.
*
* If there are less than {@code numWords} word-containing {@link LogUnit}s, shifts out
* all {@code LogUnit}s in the buffer.
*
* @param numWords the number of word-containing {@link LogUnit}s to shift out
* @return the number of actual {@code LogUnit}s shifted out
*/
protected
int
shiftOutWords
(
final
int
numWords
)
{
int
numWordContainingLogUnitsShiftedOut
=
0
;
for
(
LogUnit
logUnit
=
shiftOut
();
logUnit
!=
null
&&
numWordContainingLogUnitsShiftedOut
<
numWords
;
logUnit
=
shiftOut
())
{
if
(
logUnit
.
hasWord
())
{
numWordContainingLogUnitsShiftedOut
++;
}
}
return
numWordContainingLogUnitsShiftedOut
;
}
public
void
shiftOutAll
()
{
...
...
This diff is collapsed.
Click to expand it.
java/src/com/android/inputmethod/research/MainLogBuffer.java
+
6
−
11
View file @
56f35a10
...
...
@@ -25,7 +25,6 @@ import com.android.inputmethod.latin.define.ProductionFlag;
import
java.util.ArrayList
;
import
java.util.LinkedList
;
import
java.util.Random
;
/**
* MainLogBuffer is a FixedLogBuffer that tracks the state of LogUnits to make privacy guarantees.
...
...
@@ -100,10 +99,6 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
return
mSuggest
.
getMainDictionary
();
}
public
void
resetWordCounter
()
{
mNumWordsUntilSafeToSample
=
mNumWordsBetweenNGrams
;
}
public
void
setIsStopping
()
{
mIsStopping
=
true
;
}
...
...
@@ -201,7 +196,7 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
// Good n-gram at the front of the buffer. Publish it, disclosing details.
publish
(
logUnits
,
true
/* canIncludePrivateData */
);
shiftOutWords
(
N_GRAM_SIZE
);
resetWordCounter
()
;
mNumWordsUntilSafeToSample
=
mNumWordsBetweenNGrams
;
}
else
{
// No good n-gram at front, and buffer is full. Shift out the first word (or if there
// is none, the existing logUnits).
...
...
@@ -224,13 +219,13 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
final
boolean
canIncludePrivateData
);
@Override
protected
void
shiftOutWords
(
final
int
numWords
)
{
final
int
oldNumActualWords
=
getNumActualWords
();
super
.
shiftOutWords
(
numWords
);
final
int
numWordsShifted
=
oldNumActualWords
-
getNumActualWords
();
mNumWordsUntilSafeToSample
-=
numWordsShifted
;
protected
int
shiftOutWords
(
final
int
numWords
)
{
final
int
numWordContainingLogUnitsShiftedOut
=
super
.
shiftOutWords
(
numWords
);
mNumWordsUntilSafeToSample
=
Math
.
max
(
0
,
mNumWordsUntilSafeToSample
-
numWordContainingLogUnitsShiftedOut
);
if
(
DEBUG
)
{
Log
.
d
(
TAG
,
"wordsUntilSafeToSample now at "
+
mNumWordsUntilSafeToSample
);
}
return
numWordContainingLogUnitsShiftedOut
;
}
}
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