Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/GAP/pkg/simpcomp/src/   (Algebra von RWTH Aachen Version 4.15.1©)  Datei vom 18.2.2022 mit Größe 1 kB image not shown  

Quelle  util.cpp   Sprache: C

 
//
//  util.cpp
//  Bistellar
//
//  Created by Alexander Thumm on 07.10.11.
//  Copyright 2011 -. All rights reserved.
//

#include "util.h"
#include <stdlib.h>
#include <string.h>

size_t remove_duplicates(void * base, size_t num, size_t size, int (* comparison)(const void *, const void *))
{
    if (num == 0)
        return 0;
    
    size_t new_num = 1;
    
    const unsigned char * read = static_castconst unsigned char * >(base);
    unsigned char * write = static_castunsigned char * >(base);
    
    for (size_t i = 1; i < num; i++)
    {
        read += size;
        if ((*comparison)(read, write) != 0)
        {
            write += size;            
            if (write != read)
                memcpy(write, read, size);
            
            new_num++;
        }
    }
    
    return new_num;
}

size_t remove_from_set(void * base, size_t num, const void * base2, size_t num2, size_t size, int (* comparison)(const void *, const void *))
{
    if (num == 0 || num2 == 0)
        return 0;
    
    size_t new_num = 0;
    
    const unsigned char * read = static_castconst unsigned char * >(base);
    const unsigned char * read2 = static_castconst unsigned char *>(base2);
    unsigned char * write = static_castunsigned char * >(base);
    
    size_t i = 0;
    size_t j = 0;
    
    while (i < num)
    {
        int difference = (j < num2) ? (*comparison)(read, read2) : -1;

        if (difference < 0)
        {
            if (write != read)
                memcpy(write, read, size);
            read += size;
            write += size;
            new_num++;
            i++;
        }
        else if (difference == 0)
        {
            read += size;
            i++;
        }
        else
        {
            read2 += size;
            j++;
        }
    }
    
    return new_num;
}

94%


¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.