summaryrefslogtreecommitdiff
path: root/pikul.c
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-07-20 00:11:56 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-07-20 00:11:56 +0800
commit1264915af1cd1f47a34873360c4e88ae73a1bd33 (patch)
treec98c331871a559fe47df921e5ffd515257e53b39 /pikul.c
parent0f4b2281ee59811e72a9975dd019891eb334683e (diff)
Function to get list of just the service codes
Diffstat (limited to 'pikul.c')
-rw-r--r--pikul.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/pikul.c b/pikul.c
index df1662e..2255081 100644
--- a/pikul.c
+++ b/pikul.c
@@ -174,6 +174,21 @@ static int servicecmp(const void *service1, const void *service2)
(*(struct pikul_service * const *)service2)->code);
}
+char **pikul_codes(const char *origin, const char *destination, double weight)
+{
+ char **codes = malloc(sizeof(char *));
+ codes[0] = NULL;
+ struct pikul_services *services = pikul_services(origin, destination, weight);
+ if (!services || !services->length)
+ return codes;
+ codes = realloc(codes, (services->length + 1) * sizeof(char *));
+ size_t i = 0;
+ for (i = 0; i < services->length; i++)
+ codes[i] = services->list[i]->code;
+ codes[i] = NULL;
+ return codes;
+}
+
double pikul_cost(const char *origin, const char *destination, double weight, const char *code)
{
struct pikul_services *services = pikul_services(origin, destination, weight);