<commit_before>/*
 * Vanitygen, vanity bitcoin address generator
 * Copyright (C) 2011 <<EMAIL>>
 *
 * Vanitygen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version. 
 *
 * Vanitygen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Vanitygen.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <assert.h>

#include <pthread.h>

#include <openssl/ec.h>
#include <openssl/bn.h>
#include <openssl/rand.h>

#include <curl/curl.h>

#include "oclengine.h"
#include "pattern.h"
#include "util.h"
#include "avl.h"


const char *version = VANITYGEN_VERSION;
const int debug = 0;


/*
 * Bounty work item, which includes a pattern and a public key
 * Indexed in an AVL tree by pattern
 */

typedef struct workitem_s {
	avl_item_t avlent;
	const char *pattern;
	const char *comment;
	EC_POINT *pubkey;
	int addrtype;
	double difficulty;
	double reward;
	double value;
} workitem_t;


static int
workitem_cmp(workitem_t *a, workitem_t *b)
{
	int cmpres;
	cmpres = strcmp(a->pattern, b->pattern);
	if (!cmpres)
		cmpres = (a->reward < b->reward) ? -1 :
			((a->reward > b->reward) ? 1 : 0);
	return cmpres;
}

static workitem_t *
workitem_avl_search(avl_root_t *rootp, const char *pattern)
{
	workitem_t *vp;
	avl_item_t *itemp = rootp->ar_root;

	while (itemp) {
		int cmpres;
		vp = avl_item_entry(itemp, workitem_t, avlent);
		cmpres = strcmp(vp->pattern, pattern);
		if (cmpres > 0) {
			itemp = itemp->ai_left;
		} else {
			if (cmpres < 0) {
				itemp = itemp->ai_right;
			} else
				return vp;
		}
	}
	return NULL;
}

static workitem_t *
workitem_avl_insert(avl_root_t *rootp, workitem_t *vpnew)
{
	workitem_t *vp;
	avl_item_t *itemp = NULL;
	avl_item_t **ptrp = &rootp->ar_root;
	while (*ptrp) {
		int cmpres;
		itemp = *ptrp;
		vp = avl_item_entry(itemp, workitem_t, avlent);
		cmpres = workitem_cmp(vpnew, vp);
		if (cmpres > 0) {
			ptrp = &itemp->ai_left;<commit_msg>Insert patterns into the AVL tree in the correct order.<commit_after>/*
 * Vanitygen, vanity bitcoin address generator
 * Copyright (C) 2011 <<EMAIL>>
 *
 * Vanitygen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version. 
 *
 * Vanitygen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Vanitygen.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <assert.h>

#include <pthread.h>

#include <openssl/ec.h>
#include <openssl/bn.h>
#include <openssl/rand.h>

#include <curl/curl.h>

#include "oclengine.h"
#include "pattern.h"
#include "util.h"
#include "avl.h"


const char *version = VANITYGEN_VERSION;
const int debug = 0;


/*
 * Bounty work item, which includes a pattern and a public key
 * Indexed in an AVL tree by pattern
 */

typedef struct workitem_s {
	avl_item_t avlent;
	const char *pattern;
	const char *comment;
	EC_POINT *pubkey;
	int addrtype;
	double difficulty;
	double reward;
	double value;
} workitem_t;


static int
workitem_cmp(workitem_t *a, workitem_t *b)
{
	int cmpres;
	cmpres = strcmp(a->pattern, b->pattern);
	if (!cmpres)
		cmpres = (a->reward < b->reward) ? -1 :
			((a->reward > b->reward) ? 1 : 0);
	return cmpres;
}

static workitem_t *
workitem_avl_search(avl_root_t *rootp, const char *pattern)
{
	workitem_t *vp;
	avl_item_t *itemp = rootp->ar_root;

	while (itemp) {
		int cmpres;
		vp = avl_item_entry(itemp, workitem_t, avlent);
		cmpres = strcmp(vp->pattern, pattern);
		if (cmpres > 0) {
			itemp = itemp->ai_left;
		} else {
			if (cmpres < 0) {
				itemp = itemp->ai_right;
			} else
				return vp;
		}
	}
	return NULL;
}

static workitem_t *
workitem_avl_insert(avl_root_t *rootp, workitem_t *vpnew)
{
	workitem_t *vp;
	avl_item_t *itemp = NULL;
	avl_item_t **ptrp = &rootp->ar_root;
	while (*ptrp) {
		int cmpres;
		itemp = *ptrp;
		vp = avl_item_entry(itemp, workitem_t, avlent);
		cmpres = workitem_cmp(vp, vpnew);
		if (cmpres > 0) {
			ptrp = &itemp->ai_left;
{'fraction_non_alphanumeric': 0.11570419609472372, 'fraction_numerical': 0.004985459077690071, 'mean_word_length': 3.8883248730964466, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7082605', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1781, 'n_words': 556}