content
stringlengths 3
6.31k
| id
int64 0
123
|
|---|---|
{
match
self
.
compare_exchange
(
current
new
)
{
Ok
(
v
)
=
>
v
Err
(
v
)
=
>
v
}
}
| 100
|
{
match val {
true => write_fixval(wr, Marker::True),
false => write_fixval(wr, Marker::False)
}
}
| 101
|
{
let mut body_children = layout.children();
let body_background = Primitive::Quad {
bounds: layout.bounds(),
background: style.body_background,
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
};
let (body, mouse_interaction) = body.draw(
renderer,
&Defaults {
text: defaults::Text {
color: style.body_text_color,
},
},
body_children
.next()
.expect("Graphics: Layout should have a body content layout"),
cursor_position,
viewport,
);
(
Primitive::Group {
primitives: vec![body_background, body],
},
mouse_interaction,
)
}
| 102
|
{
connect_async_with_config(request, None).await
}
| 103
|
{
if len < 16 {
let marker = Marker::FixArray(len as u8);
try!(write_fixval(wr, marker));
Ok(marker)
} else if len < 65536 {
try!(write_marker(wr, Marker::Array16));
write_data_u16(wr, len as u16).and(Ok(Marker::Array16))
} else {
try!(write_marker(wr, Marker::Array32));
write_data_u32(wr, len).and(Ok(Marker::Array32))
}
}
| 104
|
{
eprintln!("Check if it compresses and decompresses \"Hello world!\"");
let compressed = compress(&"Hello world!".encode_utf16().collect::<Vec<u16>>());
assert_ne!(compressed, "Hello world!");
let decompressed = decompress(compressed).expect("Valid Decompress");
assert_eq!(decompressed, "Hello world!");
/*
it('compresses and decompresses null', function() {
var compressed = compress(null);
if (uint8array_mode===false){
expect(compressed).toBe('');
expect(typeof compressed).toBe(typeof '');
} else { //uint8array
expect(compressed instanceof Uint8Array).toBe(true);
expect(compressed.length).toBe(0); //empty array
}
var decompressed = decompress(compressed);
expect(decompressed).toBe(null);
});
*/
/*
it('compresses and decompresses undefined', function() {
var compressed = compress();
if (uint8array_mode===false){
expect(compressed).toBe('');
expect(typeof compressed).toBe(typeof '');
} else { //uint8array
expect(compressed instanceof Uint8Array).toBe(true);
expect(compressed.length).toBe(0); //empty array
}
var decompressed = decompress(compressed);
expect(decompressed).toBe(null);
});
*/
/*
it('decompresses null', function() {
var decompressed = decompress(null);
expect(decompressed).toBe('');
});
*/
eprintln!("Check if it compresses and decompresses an empty string");
let compressed = compress(&"".encode_utf16().collect::<Vec<u16>>());
if !bytearray {
assert_ne!(compressed, "");
// expect(typeof compressed).toBe(typeof '');
} else {
// expect(compressed instanceof Uint8Array).toBe(true);
assert!(!compressed.is_empty());
}
let decompressed = decompress(compressed).expect("Valid Decompress");
assert_eq!(decompressed, "");
eprintln!("Check if it compresses and decompresses all printable UTF-16 characters");
let mut test_string = String::new();
for i in 32..127 {
test_string.push(std::char::from_u32(i).expect("Valid Char"));
}
for i in (128 + 32)..55296 {
test_string.push(std::char::from_u32(i).expect("Valid Char"));
}
for i in 63744..65536 {
test_string.push(std::char::from_u32(i).expect("Valid Char"));
}
let compressed = compress(&test_string.encode_utf16().collect::<Vec<u16>>());
assert_ne!(compressed, test_string.as_str());
let decompressed = decompress(compressed).expect("Valid Decompress");
assert_eq!(decompressed, test_string.as_str());
eprintln!("Check if it compresses and decompresses a string that repeats");
let test_string = "aaaaabaaaaacaaaaadaaaaaeaaaaa";
let compressed = compress(&test_string.encode_utf16().collect::<Vec<u16>>());
assert_ne!(compressed, test_string);
assert!(compressed.len() < test_string.len());
let decompressed = decompress(compressed).expect("Valid Decompress");
assert_eq!(decompressed, test_string);
eprintln!("Check if it compresses and decompresses a long string");
let mut test_string = String::new();
for _ in 0..1000 {
write!(&mut test_string, "{} ", rand::thread_rng().gen::<f64>())
.expect("write rand float to string")
}
let compressed = compress(&test_string.encode_utf16().collect::<Vec<u16>>());
assert_ne!(compressed, test_string.as_str());
assert!(compressed.len() < test_string.len());
let decompressed = decompress(compressed).expect("Valid Decompress");
assert_eq!(decompressed, test_string.as_str());
}
| 105
|
{
let aff_size = std::mem::size_of::<E::G1Affine>() + std::mem::size_of::<E::G2Affine>();
let exp_size = exp_size::<E>();
let proj_size = std::mem::size_of::<E::G1>() + std::mem::size_of::<E::G2>();
((((mem as f64) * (1f64 - MEMORY_PADDING)) as usize)
- (2 * core_count * ((1 << MAX_WINDOW_SIZE) + 1) * proj_size))
/ (aff_size + exp_size)
}
| 106
|
{
matches
!
(
err
Error
:
:
InvalidColumnType
(
.
.
)
)
}
| 107
|
{
client_async_tls_with_connector_and_config(request, stream, connector, None).await
}
| 108
|
{
let
db
=
checked_memory_handle
(
)
?
;
let
s
=
Some
(
"
hello
world
!
"
)
;
let
b
=
Some
(
vec
!
[
1u8
2
3
4
]
)
;
db
.
execute
(
"
INSERT
INTO
foo
(
t
)
VALUES
(
?
1
)
"
[
&
s
]
)
?
;
db
.
execute
(
"
INSERT
INTO
foo
(
b
)
VALUES
(
?
1
)
"
[
&
b
]
)
?
;
let
mut
stmt
=
db
.
prepare
(
"
SELECT
t
b
FROM
foo
ORDER
BY
ROWID
ASC
"
)
?
;
let
mut
rows
=
stmt
.
query
(
[
]
)
?
;
{
let
row1
=
rows
.
next
(
)
?
.
unwrap
(
)
;
let
s1
:
Option
<
String
>
=
row1
.
get_unwrap
(
0
)
;
let
b1
:
Option
<
Vec
<
u8
>
>
=
row1
.
get_unwrap
(
1
)
;
assert_eq
!
(
s
.
unwrap
(
)
s1
.
unwrap
(
)
)
;
assert
!
(
b1
.
is_none
(
)
)
;
}
{
let
row2
=
rows
.
next
(
)
?
.
unwrap
(
)
;
let
s2
:
Option
<
String
>
=
row2
.
get_unwrap
(
0
)
;
let
b2
:
Option
<
Vec
<
u8
>
>
=
row2
.
get_unwrap
(
1
)
;
assert
!
(
s2
.
is_none
(
)
)
;
assert_eq
!
(
b
b2
)
;
}
Ok
(
(
)
)
}
| 109
|
{
try!(write_str_len(wr, data.len() as u32));
wr.write_all(data.as_bytes()).map_err(|err| ValueWriteError::InvalidDataWrite(WriteError(err)))
}
| 110
|
{
let
is_lock_free
=
can_transmute
:
:
<
T
AtomicUnit
>
(
)
|
can_transmute
:
:
<
T
atomic
:
:
AtomicU8
>
(
)
|
can_transmute
:
:
<
T
atomic
:
:
AtomicU16
>
(
)
|
can_transmute
:
:
<
T
atomic
:
:
AtomicU32
>
(
)
;
#
[
cfg
(
not
(
crossbeam_no_atomic_64
)
)
]
let
is_lock_free
=
is_lock_free
|
can_transmute
:
:
<
T
atomic
:
:
AtomicU64
>
(
)
;
is_lock_free
}
| 111
|
{
const
LEN
:
usize
=
97
;
#
[
allow
(
clippy
:
:
declare_interior_mutable_const
)
]
const
L
:
SeqLock
=
SeqLock
:
:
new
(
)
;
static
LOCKS
:
[
SeqLock
;
LEN
]
=
[
L
;
LEN
]
;
&
LOCKS
[
addr
%
LEN
]
}
| 112
|
{
if len < 32 {
let marker = Marker::FixStr(len as u8);
try!(write_fixval(wr, marker));
Ok(marker)
} else if len < 256 {
try!(write_marker(wr, Marker::Str8));
write_data_u8(wr, len as u8).and(Ok(Marker::Str8))
} else if len < 65536 {
try!(write_marker(wr, Marker::Str16));
write_data_u16(wr, len as u16).and(Ok(Marker::Str16))
} else {
try!(write_marker(wr, Marker::Str32));
write_data_u32(wr, len).and(Ok(Marker::Str32))
}
}
| 113
|
{
match File::open(&path) {
Err(_) => {
println!("cannot open file: {:?}", path.as_ref());
exit(1)
}
Ok(file) => file,
}
}
| 114
|
{
let mut result = Vec::new();
for crates_diff in db_data.merge_join_by(index_data, |db, index| db.name.cmp(&index.name)) {
match crates_diff {
Both(db_crate, index_crate) => {
for release_diff in db_crate
.releases
.iter()
.merge_join_by(index_crate.releases.iter(), |db_release, index_release| {
db_release.version.cmp(&index_release.version)
})
{
match release_diff {
Both(db_release, index_release) => {
let index_yanked =
index_release.yanked.expect("index always has yanked-state");
// if `db_release.yanked` is `None`, the record
// is coming from the build queue, not the `releases`
// table.
// In this case, we skip this check.
if let Some(db_yanked) = db_release.yanked {
if db_yanked != index_yanked {
result.push(Difference::ReleaseYank(
db_crate.name.clone(),
db_release.version.clone(),
index_yanked,
));
}
}
}
Left(db_release) => result.push(Difference::ReleaseNotInIndex(
db_crate.name.clone(),
db_release.version.clone(),
)),
Right(index_release) => result.push(Difference::ReleaseNotInDb(
index_crate.name.clone(),
index_release.version.clone(),
)),
}
}
}
Left(db_crate) => result.push(Difference::CrateNotInIndex(db_crate.name.clone())),
Right(index_crate) => result.push(Difference::CrateNotInDb(
index_crate.name.clone(),
index_crate
.releases
.iter()
.map(|r| r.version.clone())
.collect(),
)),
};
}
result
}
| 115
|
{
fn inner<E, CS>(mut cs: CS, left: &Scalar<E>, right: &Scalar<E>) -> Result<Scalar<E>, Error>
where
E: IEngine,
CS: ConstraintSystem<E>,
{
let scalar_type = zinc_types::ScalarType::expect_same(left.get_type(), right.get_type())?;
scalar_type.assert_signed(false)?;
let len = scalar_type.bitlength::<E>();
let left_bits = left
.to_expression::<CS>()
.into_bits_le_fixed(cs.namespace(|| "left bits"), len)?;
let right_bits = right
.to_expression::<CS>()
.into_bits_le_fixed(cs.namespace(|| "left bits"), len)?;
let result_bits = left_bits
.into_iter()
.zip(right_bits)
.enumerate()
.map(|(i, (l_bit, r_bit))| {
Boolean::xor(cs.namespace(|| format!("bit {}", i)), &l_bit, &r_bit)
})
.collect::<Result<Vec<Boolean>, SynthesisError>>()?;
let result = AllocatedNum::pack_bits_to_element(cs.namespace(|| "result"), &result_bits)?;
Ok(Scalar::new_unchecked_variable(
result.get_value(),
result.get_variable(),
scalar_type,
))
}
auto_const!(inner, cs, left, right)
}
| 116
|
{
use x86_64::instructions::segmentation::set_cs;
use x86_64::instructions::tables::load_tss;
GDT.0.load();
unsafe
{
set_cs(GDT.1.codesel);
load_tss(GDT.1.tsssel);
}
}
| 117
|
{
crate::accept_hdr_async_with_config(TokioAdapter(stream), callback, config).await
}
| 118
|
{
pub
fn
load
(
&
self
)
-
>
T
{
unsafe
{
atomic_load
(
self
.
as_ptr
(
)
)
}
}
}
| 119
|
{
let in_data = dot_vox::load(ifpath).unwrap();
let file = File::create(ofpath)?;
let mut file = LineWriter::new(file);
let len_str: String = in_data.palette.len().to_string() + "\n";
file.write_all(b"JASC\n")?;
file.write_all(b"0100\n")?;
file.write_all(len_str.as_bytes())?;
for element in &in_data.palette
{
let color: Color = (*element).into();
let color_str: String = color.into();
file.write_all((color_str + "\n").as_bytes())?;
}
Ok(())
}
| 120
|
{
try!(write_marker(wr, Marker::U16));
write_data_u16(wr, val)
}
| 121
|
{
atomic
!
{
T
a
{
a
=
&
*
(
dst
as
*
const
_
as
*
const
_
)
;
let
mut
current_raw
=
mem
:
:
transmute_copy
(
&
current
)
;
let
new_raw
=
mem
:
:
transmute_copy
(
&
new
)
;
loop
{
match
a
.
compare_exchange_weak
(
current_raw
new_raw
Ordering
:
:
AcqRel
Ordering
:
:
Acquire
)
{
Ok
(
_
)
=
>
break
Ok
(
current
)
Err
(
previous_raw
)
=
>
{
let
previous
=
mem
:
:
transmute_copy
(
&
previous_raw
)
;
if
!
T
:
:
eq
(
&
previous
&
current
)
{
break
Err
(
previous
)
;
}
/
/
The
compare
-
exchange
operation
has
failed
and
didn
'
t
store
new
.
The
/
/
failure
is
either
spurious
or
previous
was
semantically
equal
to
/
/
current
but
not
byte
-
equal
.
Let
'
s
retry
with
previous
as
the
new
/
/
current
.
current
=
previous
;
current_raw
=
previous_raw
;
}
}
}
}
{
let
guard
=
lock
(
dst
as
usize
)
.
write
(
)
;
if
T
:
:
eq
(
&
*
dst
&
current
)
{
Ok
(
ptr
:
:
replace
(
dst
new
)
)
}
else
{
let
val
=
ptr
:
:
read
(
dst
)
;
/
/
The
value
hasn
'
t
been
changed
.
Drop
the
guard
without
incrementing
the
stamp
.
guard
.
abort
(
)
;
Err
(
val
)
}
}
}
}
| 122
|
{
try!(write_marker(wr, Marker::I64));
write_data_i64(wr, val)
}
| 123
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.