Skip to content

Commit

Permalink
Recommit due to commit from wrong directory
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondrod committed Feb 5, 2022
1 parent 441d1b0 commit a1cfe94
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
11 changes: 6 additions & 5 deletions api_examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ pub extern "C" fn hidden_key(table: K) -> K{
pub extern "C" fn pick_row(object: K, index: K) -> K{
match object.get_type(){
qtype::TABLE => {
match object.get_row(&["sym"], index.get_long().unwrap() as usize){
match object.get_row(index.get_long().unwrap() as usize, &["sym"]){
Ok(row) => row,
Err(error) => new_error(error)
}
Expand Down Expand Up @@ -1119,16 +1119,17 @@ pub extern "C" fn drift(_: K)->K{
simple.as_mut_slice::<I>().copy_from_slice(&[12, 34]);
let extra=new_list(qtype::COMPOUND_LIST, 2);
extra.as_mut_slice::<K>().copy_from_slice(&[new_symbol("vague"), new_int(-3000)]);
let mut compound = simple_to_compound(simple, &[]);
let mut compound = simple_to_compound(simple, "");
compound.append(extra).unwrap()
}

/// Second example of `simple_to_compound`.
#[no_mangle]
pub extern "C" fn drift2(_: K)->K{
let simple=new_list(qtype::ENUM_LIST, 3);
simple.as_mut_slice::<J>().copy_from_slice(&[0_i64, 1, 2]);
let mut compound = simple_to_compound(simple, &["enum", "enum2", "enum"]);
let simple=new_list(qtype::ENUM_LIST, 2);
simple.as_mut_slice::<J>().copy_from_slice(&[0_i64, 1]);
let mut compound = simple_to_compound(simple, "enum");
compound.push(new_enum("enum2", 2)).unwrap();
compound.push(new_month(3)).unwrap();
compound
}
2 changes: 1 addition & 1 deletion kdbplus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kdbplus"
version = "0.3.6"
version = "0.3.7"
authors = ["diamondrod"]
edition = "2021"
license = "Apache-2.0"
Expand Down
31 changes: 16 additions & 15 deletions kdbplus/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ pub trait KUtility{
/// pub extern "C" fn print_row(object: K, index: K) -> K{
/// match object.get_type(){
/// qtype::TABLE => {
/// match object.get_row(&["sym"], index.get_long().unwrap() as usize){
/// match object.get_row(index.get_long().unwrap() as usize, &["sym"]){
/// Ok(row) => {
/// let null = unsafe{k(0, str_to_S!("{-1 \"row: \", .Q.s1 x}"), row, KNULL)};
/// decrement_reference_count(null);
Expand All @@ -652,7 +652,7 @@ pub trait KUtility{
/// q)row[table;1]
/// row: `time`sym`go`miscellaneous!(2022.01.30D07:55:47.987133353;`Green;"x";`lion)
/// ```
fn get_row(&self, enum_sources: &[&str], index: usize) -> Result<K, &'static str>;
fn get_row(&self, index: usize, enum_sources: &[&str]) -> Result<K, &'static str>;

/// Get an attribute of a q object.
/// # Example
Expand Down Expand Up @@ -946,7 +946,7 @@ impl KUtility for K{
}
}

fn get_row(&self, enum_sources: &[&str], index: usize) -> Result<K, &'static str>{
fn get_row(&self, index: usize, enum_sources: &[&str]) -> Result<K, &'static str>{
match unsafe{(**self).qtype}{
qtype::TABLE => {
let keys = unsafe{(**self).value.table}.as_mut_slice::<K>()[0];
Expand Down Expand Up @@ -2702,9 +2702,10 @@ pub fn days_to_ymd(days: I) -> I{
///
/// #[no_mangle]
/// pub extern "C" fn drift2(_: K)->K{
/// let simple=new_list(qtype::ENUM_LIST, 3);
/// simple.as_mut_slice::<J>().copy_from_slice(&[0, 1, 2]);
/// let mut compound = simple_to_compound(simple, &["enum", "enum2", "enum"]);
/// let simple=new_list(qtype::ENUM_LIST, 2);
/// simple.as_mut_slice::<J>().copy_from_slice(&[0_i64, 1]);
/// let mut compound = simple_to_compound(simple, "enum");
/// compound.push(new_enum("enum2", 2)).unwrap();
/// compound.push(new_month(3)).unwrap();
/// compound
/// }
Expand All @@ -2718,17 +2719,20 @@ pub fn days_to_ymd(days: I) -> I{
/// `vague
/// -3000i
/// q)enum: `mashroom`broccoli`cucumber
/// q)enum2: `mackerel`swordfish
/// q)enum2: `mackerel`swordfish`tuna
/// q)drift2[]
/// `enum$`mashroom
/// `enum2$`swordfish
/// `enum$`cucumber
/// `enum$`broccoli
/// `enum2$`tuna
/// 2000.04m
/// ```
/// # Note
/// To convert a list provided externally (i.e., passed from a q process), apply
/// - To convert a list provided externally (i.e., passed from a q process), apply
/// [`increment_reference_count`](fn.increment_reference_count.html) before converting the list.
pub fn simple_to_compound(simple: K, enum_sources: &[&str]) -> K{
/// - Enum elements from different enum sources must be contained in a compound list. Therefore
/// this function intentionally restricts the number of enum sources to one so that user switches
/// a simple list to a compound list when the second enum sources are provided.
pub fn simple_to_compound(simple: K, enum_source: &str) -> K{
let size=simple.len() as usize;
let compound=new_list(qtype::COMPOUND_LIST, size as J);
let compound_slice=compound.as_mut_slice::<K>();
Expand Down Expand Up @@ -2812,12 +2816,9 @@ pub fn simple_to_compound(simple: K, enum_sources: &[&str]) -> K{
}
},
qtype::ENUM_LIST => {
if enum_sources.len() < size{
return new_error("insufficient enum sources\0");
}
let simple_slice=simple.as_mut_slice::<J>();
for i in 0..size{
compound_slice[i]=new_enum(enum_sources[i], simple_slice[i]);
compound_slice[i]=new_enum(enum_source, simple_slice[i]);
}
},
_ => {
Expand Down

0 comments on commit a1cfe94

Please sign in to comment.