Search Results

Search found 4 results on 1 pages for 'mtree'.

Page 1/1 | 1 

  • Max Value of a Multiway Tree in OCaml

    - by Trigork
    I'm an IT Student and kind of a newbie to OCaml Recently, studying for an exam I found this exercise. Given: type 'a tree = Tree of 'a * 'a tree list Define a function mtree : 'a tree -'a, that returns the greatest value of all the nodes in a multiway tree, following the usual order relation in OCaml (<=) I've come to do something like this below, which, of course, is not working. let rec mtree (Tree (r, sub)) = let max_node (Tree(a, l1)) (Tree(b, l2)) = if a >= b then (Tree(a, l1)) else (Tree(b, l2)) in List.fold_left max_node r sub;; After reading an answer to this I'm posting the fixed code. let rec mtree (Tree(r,sub)) = let max_node (Tree(a, l1)) (Tree(b, l2)) = if a >= b then a else b in List.fold_left (max_node) r (List.map mtree sub);; The idea is the same, fold the list comparing the nodes making use of my local function to do so and travel through the tree by calling the function itself over the nodes lists of the consecutive levels. Is still not working, though. Now complains about max_node in the fold_left part. Error: This expression has type 'a tree -> 'a tree -> 'a but an expression was expected of type 'a tree -> 'a tree -> 'a tree And here I'm definitely lost because I can't see why does it expects to return an 'a tree

    Read the article

  • Why does this XML validation via XSD fail in libxml2 (but succeed in xmllint) and how do I fix it?

    - by mtree
    If I run this XML validation via xmllint: xmllint --noout --schema schema.xsd test.xml I get this success message: .../test.xml validates However if I run the same validation via libxml2's C API: int result = xmlSchemaValidateDoc(...) I get a return value of 1845 and this failure message: Element '{http://example.com/XMLSchema/1.0}foo': No matching global declaration available for the validation root. Which I can make absolutely no sense of. :( schema.xsd: <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "XMLSchema.dtd" > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com/XMLSchema/1.0" targetNamespace="http://example.com/XMLSchema/1.0" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="foo"> </xs:element> </xs:schema> test.xml: <?xml version="1.0" encoding="UTF-8"?> <foo xmlns="http://example.com/XMLSchema/1.0"> </foo> main.c: #include <stdio.h> #include <sys/stat.h> #include <sys/types.h> #include <string.h> #include <libxml/parser.h> #include <libxml/valid.h> #include <libxml/xmlschemas.h> u_int32_t get_file_size(const char *file_name) { struct stat buf; if ( stat(file_name, &buf) != 0 ) return(0); return (unsigned int)buf.st_size; } void handleValidationError(void *ctx, const char *format, ...) { char *errMsg; va_list args; va_start(args, format); vasprintf(&errMsg, format, args); va_end(args); fprintf(stderr, "Validation Error: %s", errMsg); free(errMsg); } int main (int argc, const char * argv[]) { const char *xsdPath = argv[1]; const char *xmlPath = argv[2]; printf("\n"); printf("XSD File: %s\n", xsdPath); printf("XML File: %s\n", xmlPath); int xmlLength = get_file_size(xmlPath); char *xmlSource = (char *)malloc(sizeof(char) * xmlLength); FILE *p = fopen(xmlPath, "r"); char c; unsigned int i = 0; while ((c = fgetc(p)) != EOF) { xmlSource[i++] = c; } printf("\n"); printf("XML Source:\n\n%s\n", xmlSource); fclose(p); printf("\n"); int result = 42; xmlSchemaParserCtxtPtr parserCtxt = NULL; xmlSchemaPtr schema = NULL; xmlSchemaValidCtxtPtr validCtxt = NULL; xmlDocPtr xmlDocumentPointer = xmlParseMemory(xmlSource, xmlLength); parserCtxt = xmlSchemaNewParserCtxt(xsdPath); if (parserCtxt == NULL) { fprintf(stderr, "Could not create XSD schema parsing context.\n"); goto leave; } schema = xmlSchemaParse(parserCtxt); if (schema == NULL) { fprintf(stderr, "Could not parse XSD schema.\n"); goto leave; } validCtxt = xmlSchemaNewValidCtxt(schema); if (!validCtxt) { fprintf(stderr, "Could not create XSD schema validation context.\n"); goto leave; } xmlSetStructuredErrorFunc(NULL, NULL); xmlSetGenericErrorFunc(NULL, handleValidationError); xmlThrDefSetStructuredErrorFunc(NULL, NULL); xmlThrDefSetGenericErrorFunc(NULL, handleValidationError); result = xmlSchemaValidateDoc(validCtxt, xmlDocumentPointer); leave: if (parserCtxt) { xmlSchemaFreeParserCtxt(parserCtxt); } if (schema) { xmlSchemaFree(schema); } if (validCtxt) { xmlSchemaFreeValidCtxt(validCtxt); } printf("\n"); printf("Validation successful: %s (result: %d)\n", (result == 0) ? "YES" : "NO", result); return 0; } console output: XSD File: /Users/dephiniteloop/Desktop/xml_validate/schema.xsd XML File: /Users/dephiniteloop/Desktop/xml_validate/test.gkml XML Source: <?xml version="1.0" encoding="UTF-8"?> <foo xmlns="http://example.com/XMLSchema/1.0"> </foo> Validation Error: Element '{http://example.com/XMLSchema/1.0}foo': No matching global declaration available for the validation root. Validation successful: NO (result: 1845) In case it matters: I'm on OSX 10.6.7 with its default libxml2.dylib (/Developer/SDKs/MacOSX10.6.sdk/usr/lib/libxml2.2.7.3.dylib)

    Read the article

  • How to tell if a freebsd jail is up to date?

    - by Martin Torhage
    I've set up a "Service Jail" in FreeBSD 8.0 according to the FreeBSD Handbook (http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/jails-application.html). After upgrading the host to the latest patch level and then performed a jail-upgrade, freebsd-fetch still reports that there are files in need of an update in the jail. Is this expected? Then how do I know if a jail is up to date? This is what I've done in more detail: After the initial setup of the jail freebsd-update fetch reported that there were no updates available neither in the host system nor in the jail. This was expected. A while later freebsd-update fetch reported that the following files where in need of an update both in the host and in the jail. /usr/lib/libssl.a /usr/lib/libssl_p.a /usr/lib/libzpool.a /usr/lib32/libssl.a /usr/lib32/libssl_p.a /usr/lib32/libzpool.a I updated the host and followed the upgrade guide for the jail (http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/jails-application.html#JAILS-SERVICE-JAILS-UPGRADING). freebsd-update fetch now reports that there are no updates available in the host but the following is the output from freebsd-update fetch in the jail: [root@bb /]# freebsd-update fetch Looking up update.FreeBSD.org mirrors... 3 mirrors found. Fetching metadata signature for 8.0-RELEASE from update5.FreeBSD.org... done. Fetching metadata index... done. Inspecting system... done. Preparing to download files... done. The following files are affected by updates, but no changes have been downloaded because the files have been modified locally: /var/db/mergemaster.mtree The following files will be updated as part of updating to 8.0-RELEASE-p2: /usr/lib/libssl.a /usr/lib/libssl_p.a /usr/lib/libzpool.a /usr/lib32/libssl.a /usr/lib32/libssl_p.a /usr/lib32/libzpool.a Shouldn't freebsd-update know that the jail is up to date or have I failed upgrading it? How am I supposed to know if a jail is up to date if freebsd-update can't tell? I'm sure I ran make cleandir twice before make buildworld. TIA

    Read the article

  • freebsd-update reports an upgraded jail as not upgraded

    - by Martin Torhage
    I've set up a "Service Jail" in FreeBSD 8.0 according to the FreeBSD Handbook (http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/jails-application.html). After upgrading the host to the latest patch level and then performed a jail-upgrade, freebsd-fetch still reports that there are files in need of an update in the jail. Is this expected? Then how do I know if a jail is up to date? This is what I've done in more detail: After the initial setup of the jail freebsd-update fetch reported that there were no updates available neither in the host system nor in the jail. This was expected. A while later freebsd-update fetch reported that the following files where in need of an update both in the host and in the jail. /usr/lib/libssl.a /usr/lib/libssl_p.a /usr/lib/libzpool.a /usr/lib32/libssl.a /usr/lib32/libssl_p.a /usr/lib32/libzpool.a I updated the host and followed the upgrade guide for the jail (http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/jails-application.html#JAILS-SERVICE-JAILS-UPGRADING). freebsd-update fetch now reports that there are no updates available in the host but the following is the output from freebsd-update fetch in the jail: [root@bb /]# freebsd-update fetch Looking up update.FreeBSD.org mirrors... 3 mirrors found. Fetching metadata signature for 8.0-RELEASE from update5.FreeBSD.org... done. Fetching metadata index... done. Inspecting system... done. Preparing to download files... done. The following files are affected by updates, but no changes have been downloaded because the files have been modified locally: /var/db/mergemaster.mtree The following files will be updated as part of updating to 8.0-RELEASE-p2: /usr/lib/libssl.a /usr/lib/libssl_p.a /usr/lib/libzpool.a /usr/lib32/libssl.a /usr/lib32/libssl_p.a /usr/lib32/libzpool.a Shouldn't freebsd-update know that the jail is up to date or have I failed upgrading it? How am I supposed to know if a jail is up to date if freebsd-update can't tell? I'm sure I ran make cleandir twice before make buildworld. TIA

    Read the article

1