summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorPranith K <pranithk@gluster.com>2011-03-10 02:20:20 +0000
committerVijay Bellur <vijay@dev.gluster.com>2011-03-10 08:09:54 -0800
commit496a04f3b2d46893635f93e5a33032969a826cd2 (patch)
tree7a877c12e0435ec45d96cc8b4df71b5f3f91e068 /libglusterfs
parent9c945fdebc195c030701257abf42c4959f97234e (diff)
libglusterfs: Add sort routine
Signed-off-by: Pranith Kumar K <pranithk@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1965 (need a cmd to get io-stat details) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1965
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/common-utils.c42
-rw-r--r--libglusterfs/src/common-utils.h4
2 files changed, 43 insertions, 3 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 931cc66fbbc..98dbeb83110 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -1684,13 +1684,13 @@ valid_internet_address (char *address)
goto out;
}
- if (valid_ipv4_address (address, length)
+ if (valid_ipv4_address (address, length)
|| valid_ipv6_address (address, length)
|| valid_host_name (address, length)) {
ret = 1;
}
-out:
+out:
return ret;
}
@@ -1725,3 +1725,41 @@ void _get_md5_str (char *out_str, size_t outlen,
snprintf(out_str + j * 2, outlen-j*2, "%02x", out[j]);
}
+
+void* gf_array_elem (void *a, int index, size_t elem_size)
+{
+ uint8_t* ptr = a;
+ return (void*)(ptr + index * elem_size);
+}
+
+void
+gf_elem_swap (void *x, void *y, size_t l) {
+ uint8_t *a = x, *b = y, c;
+ while(l--) {
+ c = *a;
+ *a++ = *b;
+ *b++ = c;
+ }
+}
+
+void
+gf_array_insertionsort (void *A, int l, int r, size_t elem_size,
+ gf_cmp cmp)
+{
+ int i = l;
+ int N = r+1;
+ void *Temp = NULL;
+ int j = 0;
+
+ for(i = l; i < N; i++) {
+ Temp = gf_array_elem (A, i, elem_size);
+ j = i - 1;
+ while((cmp (Temp, gf_array_elem (A, j, elem_size)) < 0) && j>=0)
+ {
+ gf_elem_swap (Temp, gf_array_elem (A, j, elem_size),
+ elem_size);
+ Temp = gf_array_elem (A, j, elem_size);
+ j = j-1;
+ }
+ }
+}
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 96a7c3e4ff9..b6a29b5b993 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -76,6 +76,7 @@ enum _gf_boolean
};
typedef enum _gf_boolean gf_boolean_t;
+typedef int (*gf_cmp) (void *, void *);
void gf_global_variable_init(void);
@@ -355,5 +356,6 @@ char *uuid_utoa (uuid_t uuid);
char *uuid_utoa_r (uuid_t uuid, char *dst);
void _get_md5_str (char *out_str, size_t outlen,
const uint8_t *input, int n);
+void gf_array_insertionsort (void *a, int l, int r, size_t elem_size,
+ gf_cmp cmp);
#endif /* _COMMON_UTILS_H */
-