Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
macaon
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
Container Registry
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
Franck Dary
macaon
Commits
aa16b73b
Commit
aa16b73b
authored
5 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Dict now print number of occurences
parent
72c543b6
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
common/include/Dict.hpp
+1
-1
1 addition, 1 deletion
common/include/Dict.hpp
common/src/Dict.cpp
+15
-6
15 additions, 6 deletions
common/src/Dict.cpp
with
16 additions
and
7 deletions
common/include/Dict.hpp
+
1
−
1
View file @
aa16b73b
...
...
@@ -42,7 +42,7 @@ class Dict
void
setState
(
State
state
);
State
getState
()
const
;
void
save
(
std
::
FILE
*
destination
,
Encoding
encoding
)
const
;
bool
readEntry
(
std
::
FILE
*
file
,
int
*
index
,
char
*
entry
,
Encoding
encoding
);
bool
readEntry
(
std
::
FILE
*
file
,
int
*
index
,
int
*
nbOccsEntry
,
char
*
entry
,
Encoding
encoding
);
void
printEntry
(
std
::
FILE
*
file
,
int
index
,
const
std
::
string
&
entry
,
Encoding
encoding
)
const
;
std
::
size_t
size
()
const
;
int
getNbOccs
(
int
index
)
const
;
...
...
This diff is collapsed.
Click to expand it.
common/src/Dict.cpp
+
15
−
6
View file @
aa16b73b
...
...
@@ -41,13 +41,17 @@ void Dict::readFromFile(const char * filename)
elementsToIndexes
.
reserve
(
nbEntries
);
int
entryIndex
;
int
nbOccsEntry
;
char
entryString
[
maxEntrySize
+
1
];
for
(
int
i
=
0
;
i
<
nbEntries
;
i
++
)
{
if
(
!
readEntry
(
file
,
&
entryIndex
,
entryString
,
encoding
))
if
(
!
readEntry
(
file
,
&
entryIndex
,
&
nbOccsEntry
,
entryString
,
encoding
))
util
::
myThrow
(
fmt
::
format
(
"file '{}' line {} bad format"
,
filename
,
i
));
elementsToIndexes
[
entryString
]
=
entryIndex
;
while
(
nbOccs
.
size
()
<=
entryIndex
)
nbOccs
.
emplace_back
(
0
);
nbOccs
[
entryIndex
]
=
nbOccsEntry
;
}
std
::
fclose
(
file
);
...
...
@@ -107,17 +111,19 @@ void Dict::save(std::FILE * destination, Encoding encoding) const
printEntry
(
destination
,
it
.
second
,
it
.
first
,
encoding
);
}
bool
Dict
::
readEntry
(
std
::
FILE
*
file
,
int
*
index
,
char
*
entry
,
Encoding
encoding
)
bool
Dict
::
readEntry
(
std
::
FILE
*
file
,
int
*
index
,
int
*
nbOccsEntry
,
char
*
entry
,
Encoding
encoding
)
{
if
(
encoding
==
Encoding
::
Ascii
)
{
static
std
::
string
readFormat
=
"%d
\t
%"
+
std
::
to_string
(
maxEntrySize
)
+
"[^
\n
]
\n
"
;
return
fscanf
(
file
,
readFormat
.
c_str
(),
index
,
entry
)
==
2
;
static
std
::
string
readFormat
=
"%d
\t
%
d
\t
%
"
+
std
::
to_string
(
maxEntrySize
)
+
"[^
\n
]
\n
"
;
return
fscanf
(
file
,
readFormat
.
c_str
(),
index
,
nbOccsEntry
,
entry
)
==
3
;
}
else
{
if
(
std
::
fread
(
index
,
sizeof
*
index
,
1
,
file
)
!=
1
)
return
false
;
if
(
std
::
fread
(
nbOccsEntry
,
sizeof
*
nbOccsEntry
,
1
,
file
)
!=
1
)
return
false
;
for
(
unsigned
int
i
=
0
;
i
<
maxEntrySize
;
i
++
)
{
if
(
std
::
fread
(
entry
+
i
,
1
,
1
,
file
)
!=
1
)
...
...
@@ -131,14 +137,17 @@ bool Dict::readEntry(std::FILE * file, int * index, char * entry, Encoding encod
void
Dict
::
printEntry
(
std
::
FILE
*
file
,
int
index
,
const
std
::
string
&
entry
,
Encoding
encoding
)
const
{
auto
entryNbOccs
=
getNbOccs
(
index
);
if
(
encoding
==
Encoding
::
Ascii
)
{
static
std
::
string
printFormat
=
"%d
\t
%s
\n
"
;
fprintf
(
file
,
printFormat
.
c_str
(),
index
,
entry
.
c_str
());
static
std
::
string
printFormat
=
"%d
\t
%
d
\t
%
s
\n
"
;
fprintf
(
file
,
printFormat
.
c_str
(),
index
,
entryNbOccs
,
entry
.
c_str
());
}
else
{
std
::
fwrite
(
&
index
,
sizeof
index
,
1
,
file
);
std
::
fwrite
(
&
entryNbOccs
,
sizeof
entryNbOccs
,
1
,
file
);
std
::
fwrite
(
entry
.
c_str
(),
1
,
entry
.
size
()
+
1
,
file
);
}
}
...
...
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