Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joshua
wendelin.core
Commits
16b19477
Commit
16b19477
authored
Oct 25, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
969dbe4b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
38 deletions
+52
-38
wcfs/internal/wcfs_misc.cpp
wcfs/internal/wcfs_misc.cpp
+15
-15
wcfs/internal/wcfs_misc.h
wcfs/internal/wcfs_misc.h
+37
-0
wcfs/internal/wcfs_virtmem.cpp
wcfs/internal/wcfs_virtmem.cpp
+0
-23
No files found.
wcfs/internal/wcfs_misc.cpp
View file @
16b19477
...
...
@@ -55,37 +55,37 @@ tuple<File, error> open(const string &path, int flags, mode_t mode) {
}
error
File
::
close
()
{
File
*
f
=
this
;
File
&
f
=
*
this
;
int
err
=
::
close
(
f
->
_fd
);
int
err
=
::
close
(
f
.
_fd
);
if
(
err
!=
0
)
return
f
->
_errno
(
"close"
);
f
->
_fd
=
-
1
;
return
f
.
_errno
(
"close"
);
f
.
_fd
=
-
1
;
return
nil
;
}
tuple
<
int
,
error
>
File
::
read
(
void
*
buf
,
size_t
count
)
{
File
*
f
=
this
;
File
&
f
=
*
this
;
int
n
;
n
=
::
read
(
f
->
_fd
,
buf
,
count
);
n
=
::
read
(
f
.
_fd
,
buf
,
count
);
if
(
n
==
0
)
return
make_tuple
(
n
,
io
::
EOF_
);
if
(
n
<
0
)
return
make_tuple
(
0
,
f
->
_errno
(
"read"
));
return
make_tuple
(
0
,
f
.
_errno
(
"read"
));
return
make_tuple
(
n
,
nil
);
}
tuple
<
int
,
error
>
File
::
write
(
const
void
*
buf
,
size_t
count
)
{
File
*
f
=
this
;
File
&
f
=
*
this
;
int
n
,
wrote
=
0
;
// NOTE contrary to write(2) we have to write all data as io.Writer requires.
while
(
count
!=
0
)
{
n
=
::
write
(
f
->
_fd
,
buf
,
count
);
n
=
::
write
(
f
.
_fd
,
buf
,
count
);
if
(
n
<
0
)
return
make_tuple
(
wrote
,
f
->
_errno
(
"write"
));
return
make_tuple
(
wrote
,
f
.
_errno
(
"write"
));
wrote
+=
n
;
buf
=
((
const
char
*
)
buf
)
+
n
;
...
...
@@ -96,19 +96,19 @@ tuple <int, error> File::write(const void *buf, size_t count) {
}
error
File
::
stat
(
struct
stat
*
st
)
{
File
*
f
=
this
;
File
&
f
=
*
this
;
int
err
=
fstat
(
f
->
_fd
,
st
);
int
err
=
fstat
(
f
.
_fd
,
st
);
if
(
err
!=
0
)
return
f
->
_errno
(
"stat"
);
return
f
.
_errno
(
"stat"
);
return
nil
;
}
// _errno returns error corresponding to op(file) and errno.
error
File
::
_errno
(
const
char
*
op
)
{
File
*
f
=
this
;
return
_pathError
(
op
,
f
->
_path
,
errno
);
File
&
f
=
*
this
;
return
_pathError
(
op
,
f
.
_path
,
errno
);
}
// _pathError returns os.PathError-like for op/path and system error
...
...
wcfs/internal/wcfs_misc.h
View file @
16b19477
...
...
@@ -125,4 +125,41 @@ error errorf (const char *format, ...)
}
// fmt::
// ---- misc ----
#include <unordered_map>
#include <unordered_set>
// dict wraps unordered_map into ergonomic interface.
template
<
typename
Key
,
typename
Value
>
struct
dict
:
std
::
unordered_map
<
Key
,
Value
>
{
// has returns whether dict has element k.
bool
has
(
const
Key
&
k
)
const
{
const
dict
&
d
=
*
this
;
return
d
.
find
(
k
)
!=
d
.
end
();
}
// get implements `d[k] -> (v, ok)`.
tuple
<
Value
,
bool
>
get
(
const
Key
&
k
)
const
{
const
dict
&
d
=
*
this
;
auto
_
=
d
.
find
(
k
);
if
(
_
==
d
.
end
())
return
make_tuple
(
Value
(),
false
);
return
make_tuple
(
_
->
second
,
true
);
}
};
// set wraps unordered_set into ergonomic interface.
template
<
typename
Key
>
struct
set
:
std
::
unordered_set
<
Key
>
{
// has returns whether set has element k.
bool
has
(
const
Key
&
k
)
const
{
const
set
&
s
=
*
this
;
return
s
.
find
(
k
)
!=
s
.
end
();
}
};
#endif
wcfs/internal/wcfs_virtmem.cpp
View file @
16b19477
...
...
@@ -34,8 +34,6 @@ using namespace golang;
#include <wendelin/bigfile/ram.h>
#include <wendelin/bug.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <sys/types.h>
...
...
@@ -48,27 +46,6 @@ using namespace golang;
#include "wcfs_misc.h"
template
<
typename
Key
,
typename
Value
>
struct
dict
:
std
::
unordered_map
<
Key
,
Value
>
{
// has returns whether container d (e.g. dict) has element k.
bool
has
(
const
Key
&
k
)
const
{
const
dict
*
d
=
this
;
return
d
->
find
(
k
)
!=
d
->
end
();
}
// get implements `d[k] -> (v, ok)`.
tuple
<
Value
,
bool
>
get
(
const
Key
&
k
)
const
{
const
dict
*
d
=
this
;
auto
_
=
d
->
find
(
k
);
if
(
_
==
d
->
end
())
return
make_tuple
(
Value
(),
false
);
return
make_tuple
(
_
->
second
,
true
);
}
};
template
<
typename
Key
>
using
set
=
std
::
unordered_set
<
Key
>
;
using
std
::
vector
;
typedef
uint64_t
Tid
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment