<commit_before>#include "circle.h"


void *Circle_next(Circle *self){
	void *next = FLList_next(&self->list, self->item);
	return next? next : self->list.firstElement;
}


void Circle_init(Circle *self, size_t elementSize){
	self->item = NULL;
	FLList_init(&self->list, elementSize);
}


void Circle_clean(Circle *self){
	FLList_clean(&self->list);
	self->item = NULL;
}


void *Circle_hook(Circle *self){
	return Circle_next(self);
}


void Circle_fetch(Circle *self, void *dest){
	void *source = Circle_next(self);
	memmove(dest, source, self->list.elementSize);
}


void Circle_shift(Circle *self){
	if(self->item)
		self->item = Circle_next(self);
}


int Circle_insert(Circle *self, void *data){
	if(self->item){
		return FLList_insertAfter(&self->list, self->item, data);
	}
	int r = FLList_insert(&self->list, data, 0);
	self->item = self->list.firstElement;
	return r;
}


void Circle_remove(Circle *self){
	if(Circle_next(self) == self->list.firstElement){
		if(FLList_next(&self->list, self->list.firstElement))
			self->item = NULL;
		FLList_remove(&self->list, 0);
	} else {
		FLList_removeNext(&self->list, self->item);
	}
}


void Circle_each(Circle *self, void (*function)(void*)){
	FLList_each(&self->list, function);
}<commit_msg>Fixed bug in circularly-linked list.<commit_after>#include "circle.h"


void *Circle_next(Circle *self){
	void *next = FLList_next(&self->list, self->item);
	return next? next : self->list.firstElement;
}


void Circle_init(Circle *self, size_t elementSize){
	self->item = NULL;
	FLList_init(&self->list, elementSize);
}


void Circle_clean(Circle *self){
	FLList_clean(&self->list);
	self->item = NULL;
}


void *Circle_hook(Circle *self){
	return Circle_next(self);
}


void Circle_fetch(Circle *self, void *dest){
	void *source = Circle_next(self);
	memmove(dest, source, self->list.elementSize);
}


void Circle_shift(Circle *self){
	if(self->item)
		self->item = Circle_next(self);
}


int Circle_insert(Circle *self, void *data){
	if(self->item){
		return FLList_insertAfter(&self->list, self->item, data);
	} else {
		int r = FLList_insert(&self->list, data, 0);
		self->item = self->list.firstElement;
		return r;
	}
}


void Circle_remove(Circle *self){
	if(Circle_next(self) == self->list.firstElement)
		FLList_remove(&self->list, 0);
	else 
		FLList_removeNext(&self->list, self->item);
	if(FLList_isEmpty(&self->list))
		self->item = NULL;
}


void Circle_each(Circle *self, void (*function)(void*)){
	FLList_each(&self->list, function);
}
{'fraction_non_alphanumeric': 0.16966786714685875, 'fraction_numerical': 0.001600640256102441, 'mean_word_length': 5.410256410256411, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6564932', 'n_tokens_mistral': 959, 'n_tokens_neox': 937, 'n_words': 184}