ObjFW  Check-in [a747ad5478]

Overview
Comment:quicksort: Reduce used space.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a747ad5478321fc704efc1397eff979effca61cdd8f6f20420b00db68e071710
User & Date: js on 2012-12-07 14:50:34
Other Links: manifest | tags
Context
2012-12-09
12:13
Split OFHTTPRequest into OFHTTP{Client,Request}. check-in: 2b7a70e246 user: js tags: trunk
2012-12-07
14:50
quicksort: Reduce used space. check-in: a747ad5478 user: js tags: trunk
13:57
Revert several OFHashMap related commits. check-in: 6712442fad user: js tags: trunk
Changes

Modified src/OFMutableArray.m from [ef9ecd25ad] to [7a6a7331fd].

37
38
39
40
41
42
43

44
45
46
47
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

@interface OFMutableArray_placeholder: OFMutableArray
@end

static void
quicksort(OFMutableArray *array, size_t left, size_t right)
{

	size_t i, j;
	id pivot;

	if (left >= right)
		return;

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

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

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

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

	if ([[array objectAtIndex: i] compare: pivot] == OF_ORDERED_DESCENDING)

		[array exchangeObjectAtIndex: i
			   withObjectAtIndex: right];

	if (i > 0)


		quicksort(array, left, i - 1);

	quicksort(array, i + 1, right);





}

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







>
|
|

<
<
<
|
|
|

|
|
|
|

|
|
|

|
|
|
|

|
>
|
|

|
>
>
|
>
|
>
>
>
>
>







37
38
39
40
41
42
43
44
45
46
47



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

@interface OFMutableArray_placeholder: OFMutableArray
@end

static void
quicksort(OFMutableArray *array, size_t left, size_t right)
{
	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] !=
			    OF_ORDERED_DESCENDING && i < right)
				i++;

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

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

		if ([[array objectAtIndex: i] compare: pivot] ==
		    OF_ORDERED_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);
			} else {
				quicksort(array, left, i - 1);
				left = i + 1;
			}
		} else
			left = i + 1;
	}
}

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