mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
use index inf queue
This commit is contained in:
parent
2c3d56308d
commit
1afc45604d
@ -165,3 +165,18 @@ TEST(args, mem) {
|
||||
EXPECT_EQ(pikaMemNow(), mem);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(args, index) {
|
||||
Args* args = New_args(NULL);
|
||||
args_pushArg(args, arg_setInt(NULL, (char*)"", 1));
|
||||
args_pushArg(args, arg_setFloat(NULL, (char*)"", 2.4));
|
||||
|
||||
int a = arg_getInt(args_getArg_index(args, 1));
|
||||
float b = arg_getFloat(args_getArg_index(args, 0));
|
||||
/* assert */
|
||||
EXPECT_EQ(a, 1);
|
||||
EXPECT_FLOAT_EQ(b, 2.4);
|
||||
/* check memory */
|
||||
args_deinit(args);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
@ -70,8 +70,9 @@ int32_t args_setStr(Args* self, char* name, char* strIn) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
void args_pushArg(Args* self, Arg* arg) {
|
||||
int args_pushArg(Args* self, Arg* arg) {
|
||||
link_addNode(self, arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* args_getBuff(Args* self, int32_t size) {
|
||||
|
@ -96,7 +96,8 @@ int32_t args_foreach(Args* self,
|
||||
|
||||
char* args_getBuff(Args* self, int32_t size);
|
||||
uint8_t args_setLiteral(Args* self, char* targetArgName, char* literal);
|
||||
void args_pushArg(Args* self, Arg* arg);
|
||||
int args_pushArg(Args* self, Arg* arg);
|
||||
Arg* args_getArg_index(Args* self, int index);
|
||||
|
||||
Args* New_args(Args* args);
|
||||
#endif
|
||||
|
@ -26,13 +26,12 @@
|
||||
*/
|
||||
|
||||
#include "dataQueue.h"
|
||||
#include "dataArgs.h"
|
||||
#include "PikaPlatform.h"
|
||||
#include "dataArgs.h"
|
||||
|
||||
Queue* New_queue(void) {
|
||||
Args* args = New_args(NULL);
|
||||
args_setInt(args, "t", 0);
|
||||
args_setInt(args, "b", 0);
|
||||
args_setInt(args, "offset", 0);
|
||||
Queue* queue = args;
|
||||
return queue;
|
||||
}
|
||||
@ -45,21 +44,23 @@ int32_t queue_deinit(Queue* queue) {
|
||||
|
||||
int32_t queue_pushArg(Queue* queue, Arg* arg) {
|
||||
Args* args = queue;
|
||||
uint64_t top = args_getInt(args, "t");
|
||||
int offset = args_getInt(args, "offset");
|
||||
/* add top */
|
||||
args_setInt(args, "t", top + 1);
|
||||
args_setInt(args, "offset", offset + 1);
|
||||
char buff[11];
|
||||
arg = arg_setName(arg, fast_itoa(buff, top));
|
||||
return args_setArg(args, arg);
|
||||
return args_pushArg(args, arg);
|
||||
}
|
||||
|
||||
Arg* queue_popArg(Queue* queue) {
|
||||
Args* args = queue;
|
||||
uint64_t bottom = args_getInt(args, "b");
|
||||
int offset = args_getInt(args, "offset");
|
||||
if (offset - 1 < 0) {
|
||||
return NULL;
|
||||
}
|
||||
/* add bottom */
|
||||
args_setInt(args, "b", bottom + 1);
|
||||
args_setInt(args, "offset", offset - 1);
|
||||
char buff[11];
|
||||
Arg* res = args_getArg(args, fast_itoa(buff, bottom));
|
||||
Arg* res = args_getArg_index(args, offset - 1);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user