ObjFW  Check-in [48f316733e]

Overview
Comment:OFMutableArray: Fix quicksort.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 48f316733e5fcf9d3ce8a0e5ab267e4465a5240cae264026a0a10c3c0d3447df
User & Date: js on 2013-01-19 06:36:13
Other Links: manifest | tags
Context
2013-01-22
02:31
OFStream: Add property for writeBufferEnabled. check-in: b96b150ce3 user: js tags: trunk
2013-01-19
06:36
OFMutableArray: Fix quicksort. check-in: 48f316733e user: js tags: trunk
02:44
OFConstantString: Add missing methods. check-in: 35491549a6 user: js tags: trunk
Changes

Modified src/OFMutableArray.m from [c800430259] to [3a62a4c2fe].

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
		descending = OF_ORDERED_ASCENDING;
	} else {
		ascending = OF_ORDERED_ASCENDING;
		descending = OF_ORDERED_DESCENDING;
	}

	while (left < right) {
		size_t i, j;
		id pivot;

		i = left;
		j = right - 1;
		pivot = [array objectAtIndex: right];

		do {
			while ([[array objectAtIndex: i] compare: pivot] !=
			    descending && i < right)
				i++;

			while ([[array objectAtIndex: j] compare: pivot] !=
			    ascending && j > left)
				j--;

			if (i < j)
				[array exchangeObjectAtIndex: i
					   withObjectAtIndex: j];
		} while (i < j);

		if ([[array objectAtIndex: i] compare: pivot] == descending)
			[array exchangeObjectAtIndex: i
				   withObjectAtIndex: right];

		if (i > 0) {
			if (i > left && i - 1 - left > right - i - 1) {
				right = i - 1;
				quicksort(array, i + 1, right, options);
			} else {
				quicksort(array, left, i - 1, options);
				left = i + 1;
			}
		} else
			left = i + 1;
	}
}

@implementation OFMutableArray_placeholder
- init
{
	return (id)[[OFMutableArray_adjacent alloc] init];







|
<
<
<
|
|



















|
<
<
<
<
|
<
|
<
|







48
49
50
51
52
53
54
55



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77




78

79

80
81
82
83
84
85
86
87
		descending = OF_ORDERED_ASCENDING;
	} else {
		ascending = OF_ORDERED_ASCENDING;
		descending = OF_ORDERED_DESCENDING;
	}

	while (left < right) {
		size_t i = left;



		size_t j = right - 1;
		id pivot = [array objectAtIndex: right];

		do {
			while ([[array objectAtIndex: i] compare: pivot] !=
			    descending && i < right)
				i++;

			while ([[array objectAtIndex: j] compare: pivot] !=
			    ascending && j > left)
				j--;

			if (i < j)
				[array exchangeObjectAtIndex: i
					   withObjectAtIndex: j];
		} while (i < j);

		if ([[array objectAtIndex: i] compare: pivot] == descending)
			[array exchangeObjectAtIndex: i
				   withObjectAtIndex: right];

		if (i > 0)




			quicksort(array, left, i - 1, options);



		left = i + 1;
	}
}

@implementation OFMutableArray_placeholder
- init
{
	return (id)[[OFMutableArray_adjacent alloc] init];