]>
git.saurik.com Git - apple/icu.git/blob - icuSources/layoutex/LXUtilities.cpp
b8561cbe9bbf5faa8aec7385f6033026529eca81
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (C) 2002-2003, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
10 #include "layout/LETypes.h"
11 #include "LXUtilities.h"
16 // Finds the high bit by binary searching
17 // through the bits in n.
19 le_int8
LXUtilities::highBit(le_int32 value
)
27 if (value
>= 1 << 16) {
32 if (value
>= 1 << 8) {
37 if (value
>= 1 << 4) {
42 if (value
>= 1 << 2) {
47 if (value
>= 1 << 1) {
55 le_int32
LXUtilities::search(le_int32 value
, const le_int32 array
[], le_int32 count
)
57 le_int32 power
= 1 << highBit(count
);
58 le_int32 extra
= count
- power
;
59 le_int32 probe
= power
;
62 if (value
>= array
[extra
]) {
66 while (probe
> (1 << 0)) {
69 if (value
>= array
[index
+ probe
]) {
77 void LXUtilities::reverse(le_int32 array
[], le_int32 length
)
81 for (front
= 0, back
= length
- 1; front
< back
; front
+= 1, back
-= 1) {
82 le_int32 swap
= array
[front
];
84 array
[front
] = array
[back
];
89 void LXUtilities::reverse(float array
[], le_int32 length
)
93 for (front
= 0, back
= length
- 1; front
< back
; front
+= 1, back
-= 1) {
94 float swap
= array
[front
];
96 array
[front
] = array
[back
];