summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-10-24 16:29:18 -0200
committerSangHyeon Jade Lee <dltkdgus1764@gmail.com>2017-11-15 17:06:45 +0900
commit8588c531874fb7482dfba14c52b67a4519d22297 (patch)
treeda51bf72aac0203e43df1b087695a64d5e78d1c9
parente8d513d59562d38b6272b756e3ead578e6bc6cb9 (diff)
elm: SegArray insertion fix
-rw-r--r--src/lib/elementary/efl_ui_list_segarray.c50
-rw-r--r--src/lib/elementary/efl_ui_list_segarray.h2
2 files changed, 29 insertions, 23 deletions
diff --git a/src/lib/elementary/efl_ui_list_segarray.c b/src/lib/elementary/efl_ui_list_segarray.c
index 48bdf25c8d..d5bd1ae910 100644
--- a/src/lib/elementary/efl_ui_list_segarray.c
+++ b/src/lib/elementary/efl_ui_list_segarray.c
@@ -20,21 +20,17 @@ static int _search_lookup_cb(Eina_Rbtree const* rbtree, const void* key, int len
20{ 20{
21 Efl_Ui_List_SegArray_Node const* node = (void const*)rbtree; 21 Efl_Ui_List_SegArray_Node const* node = (void const*)rbtree;
22 int index = *(int*)key; 22 int index = *(int*)key;
23 DBG("searching for %d", index);
24 if(index < node->first) 23 if(index < node->first)
25 { 24 {
26 DBG("index is less than index"); 25 return 1;
27 return -1;
28 } 26 }
29 else if(index < node->first + node->length) 27 else if(index < node->first + node->length)
30 { 28 {
31 DBG("index is within bounds, found it");
32 return 0; 29 return 0;
33 } 30 }
34 else 31 else
35 { 32 {
36 DBG("we're after first %d max %d index %d", node->first, node->max, index); 33 return -1;
37 return 1;
38 } 34 }
39} 35}
40 36
@@ -44,7 +40,7 @@ static int _insert_lookup_cb(Eina_Rbtree const* rbtree, const void* key, int len
44 int index = *(int*)key; 40 int index = *(int*)key;
45 if(index < node->first) 41 if(index < node->first)
46 { 42 {
47 return -1; 43 return 1;
48 } 44 }
49 else if(index < node->first + node->max) 45 else if(index < node->first + node->max)
50 { 46 {
@@ -52,20 +48,17 @@ static int _insert_lookup_cb(Eina_Rbtree const* rbtree, const void* key, int len
52 } 48 }
53 else 49 else
54 { 50 {
55 return 1; 51 return -1;
56 } 52 }
57} 53}
58 54
59static Eina_Rbtree_Direction _rbtree_compare(Eina_Rbtree const* left, Eina_Rbtree const* right, void* data EINA_UNUSED) 55static Eina_Rbtree_Direction _rbtree_compare(Efl_Ui_List_SegArray_Node const* left,
56 Efl_Ui_List_SegArray_Node const* right, void* data EINA_UNUSED)
60{ 57{
61 Efl_Ui_List_SegArray_Node const *nl = (void const*)left, *nr = (void const*)right; 58 if(left->first < right->first)
62 return !nl ? EINA_RBTREE_LEFT : 59 return EINA_RBTREE_LEFT;
63 ( 60 else
64 !nr ? EINA_RBTREE_RIGHT : 61 return EINA_RBTREE_RIGHT;
65 (
66 nl->first < nr->first ? EINA_RBTREE_LEFT : EINA_RBTREE_RIGHT
67 )
68 );
69} 62}
70 63
71static Efl_Ui_List_SegArray_Node* 64static Efl_Ui_List_SegArray_Node*
@@ -77,7 +70,14 @@ _alloc_node(Efl_Ui_List_SegArray* segarray, int first, int max)
77 node = calloc(1, sizeof(Efl_Ui_List_SegArray_Node) + max*sizeof(Efl_Ui_List_Item*)); 70 node = calloc(1, sizeof(Efl_Ui_List_SegArray_Node) + max*sizeof(Efl_Ui_List_Item*));
78 node->first = first; 71 node->first = first;
79 node->max = max; 72 node->max = max;
80 segarray->root = eina_rbtree_inline_insert(segarray->root, EINA_RBTREE_GET(node), &_rbtree_compare, NULL); 73 void* tmp = segarray->root;
74 segarray->root = (void*)eina_rbtree_inline_insert(EINA_RBTREE_GET(segarray->root), EINA_RBTREE_GET(node),
75 EINA_RBTREE_CMP_NODE_CB(&_rbtree_compare), NULL);
76 //assert(tmp != segarray->root);
77 if(tmp != segarray->root)
78 DBG("changed root node");
79 else
80 DBG("NOT changed root node");
81 segarray->node_count++; 81 segarray->node_count++;
82 return node; 82 return node;
83} 83}
@@ -108,7 +108,7 @@ void efl_ui_list_segarray_insert_accessor(Efl_Ui_List_SegArray* segarray, int fi
108 if(segarray->root) 108 if(segarray->root)
109 { 109 {
110 { 110 {
111 Eina_Iterator* pre_iterator = eina_rbtree_iterator_prefix(segarray->root); 111 Eina_Iterator* pre_iterator = eina_rbtree_iterator_prefix(EINA_RBTREE_GET(segarray->root));
112 if(!eina_iterator_next(pre_iterator, (void**)&first_node)) 112 if(!eina_iterator_next(pre_iterator, (void**)&first_node))
113 first_node = NULL; 113 first_node = NULL;
114 else 114 else
@@ -154,7 +154,8 @@ void efl_ui_list_segarray_insert_accessor(Efl_Ui_List_SegArray* segarray, int fi
154 154
155 DBG("insert is in the middle"); 155 DBG("insert is in the middle");
156 156
157 node = (void*)eina_rbtree_inline_lookup(segarray->root, &idx, sizeof(idx), &_insert_lookup_cb, NULL); 157 node = (void*)eina_rbtree_inline_lookup(EINA_RBTREE_GET(segarray->root),
158 &idx, sizeof(idx), &_insert_lookup_cb, NULL);
158 if(node) 159 if(node)
159 { 160 {
160 assert(node->length < node->max); 161 assert(node->length < node->max);
@@ -164,7 +165,11 @@ void efl_ui_list_segarray_insert_accessor(Efl_Ui_List_SegArray* segarray, int fi
164 } 165 }
165 else 166 else
166 { 167 {
167 DBG("no node to add item!"); 168 DBG("no node to add item for index %d!", i + first);
169 node = _alloc_node(segarray, i + first, segarray->array_initial_size);
170 node->pointers[0] = _create_item(children, first + i);
171 node->length++;
172 segarray->count++;
168 } 173 }
169 } 174 }
170 /* else // suffix'ing */ 175 /* else // suffix'ing */
@@ -197,7 +202,8 @@ _efl_ui_list_segarray_accessor_get_at(Efl_Ui_List_Segarray_Eina_Accessor* acc,
197 int idx, void** data) 202 int idx, void** data)
198{ 203{
199 Efl_Ui_List_SegArray_Node* node; 204 Efl_Ui_List_SegArray_Node* node;
200 node = (void*)eina_rbtree_inline_lookup(acc->segarray->root, &idx, sizeof(idx), &_search_lookup_cb, NULL); 205 node = (void*)eina_rbtree_inline_lookup(EINA_RBTREE_GET(acc->segarray->root),
206 &idx, sizeof(idx), &_search_lookup_cb, NULL);
201 if(node) 207 if(node)
202 { 208 {
203 if(node->first <= idx && node->first + node->length > idx) 209 if(node->first <= idx && node->first + node->length > idx)
diff --git a/src/lib/elementary/efl_ui_list_segarray.h b/src/lib/elementary/efl_ui_list_segarray.h
index 2ce2e1d9ae..c161ee3c2d 100644
--- a/src/lib/elementary/efl_ui_list_segarray.h
+++ b/src/lib/elementary/efl_ui_list_segarray.h
@@ -18,7 +18,7 @@ typedef struct _Efl_Ui_List_SegArray_Node
18 18
19typedef struct _Efl_Ui_List_SegArray 19typedef struct _Efl_Ui_List_SegArray
20{ 20{
21 Eina_Rbtree *root; // of Efl_Ui_List_SegArray_Nodea 21 Efl_Ui_List_SegArray_Node *root; // of Efl_Ui_List_SegArray_Nodea
22 22
23 int array_initial_size; 23 int array_initial_size;
24 int node_count; 24 int node_count;