| Function report | 
| Source Code: lib\assoc_array.c | Create Date:2022-07-28 06:54:40 | 
| Last Modify:2020-03-12 14:18:49 | Copyright©Brick | 
| home page | Tree | 
| Annotation kernel can get tool activity | Download SCCT | Chinese | 
Name:assoc_array_gc - Garbage collect an associative array
Proto:int assoc_array_gc(struct assoc_array *array, const struct assoc_array_ops *ops, bool (*iterator)(void *object, void *iterator_data), void *iterator_data)
Type:int
Parameter:
| Type | Parameter | Name | 
|---|---|---|
| struct assoc_array * | array | |
| const struct assoc_array_ops * | ops | |
| bool (* | iterator | |
| void * | iterator_data | 
| 1469 | If Not The node at the root of the tree Then Return 0 | 
| 1472 | edit = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc). | 
| 1477 | ops_for_excised_subtree = ops | 
| 1481 | new_root = new_parent = NULL | 
| 1482 | new_ptr_pp = new_root | 
| 1485 | descend : | 
| 1489 | If assoc_array_ptr_is_shortcut(cursor) Then | 
| 1492 | keylen >>= ASSOC_ARRAY_KEY_CHUNK_SHIFT | 
| 1493 | new_s = kmalloc(sizeof(structassoc_array_shortcut) + keylen * sizeof(unsignedlong), GFP_KERNEL) | 
| 1498 | No 3D Now!(new_s, shortcut, (sizeof(structassoc_array_shortcut) + keylen * sizeof(unsignedlong))) | 
| 1500 | back_pointer = new_parent | 
| 1501 | parent_slot = parent_slot | 
| 1502 | new_ptr_pp = new_parent = assoc_array_shortcut_to_ptr(new_s) | 
| 1503 | new_ptr_pp = next_node | 
| 1508 | node = assoc_array_ptr_to_node(cursor) | 
| 1509 | new_n = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc). | 
| 1513 | back_pointer = new_parent | 
| 1514 | parent_slot = parent_slot | 
| 1515 | new_ptr_pp = new_parent = assoc_array_node_to_ptr(new_n) | 
| 1516 | new_ptr_pp = NULL | 
| 1517 | slot = 0 | 
| 1519 | continue_node : | 
| 1521 | When slot < Number of slots per node cycle | 
| 1523 | If Not ptr Then Continue | 
| 1526 | If assoc_array_ptr_is_leaf(ptr) Then | 
| 1527 | If iterator(assoc_array_ptr_to_leaf(ptr), iterator_data) Then slots[slot] = ptr | 
| 1533 | Continue | 
| 1536 | new_ptr_pp = slots[slot] | 
| 1538 | Go to descend | 
| 1546 | nr_leaves_on_branch = 0 | 
| 1547 | nr_free = 0 | 
| 1548 | When slot < Number of slots per node cycle | 
| 1552 | Else if assoc_array_ptr_is_leaf(ptr) Then nr_leaves_on_branch++ | 
| 1555 | pr_devel("free=%d, leaves=%lu\n", nr_free, nr_leaves_on_branch) | 
| 1558 | next_slot = 0 | 
| 1559 | When slot < Number of slots per node cycle | 
| 1564 | If Not ptr || assoc_array_ptr_is_leaf(ptr) Then Continue | 
| 1567 | s = NULL | 
| 1568 | If assoc_array_ptr_is_shortcut(ptr) Then | 
| 1569 | s = assoc_array_ptr_to_shortcut(ptr) | 
| 1573 | child = assoc_array_ptr_to_node(ptr) | 
| 1576 | If nr_leaves_on_branch <= nr_free + 1 Then | 
| 1578 | pr_devel("[%d] fold node %lu/%d [nx %d]\n", slot, nr_leaves_on_branch, nr_free + 1, next_slot) | 
| 1588 | nr_free++ | 
| 1591 | When i < Number of slots per node cycle | 
| 1593 | If Not p Then Continue | 
| 1595 | BUG_ON(assoc_array_ptr_is_meta(p)) | 
| 1597 | next_slot++ | 
| 1598 | BUG_ON(next_slot >= Number of slots per node ) | 
| 1600 | nr_free-- | 
| 1603 | Else | 
| 1604 | pr_devel("[%d] retain node %lu/%d [nx %d]\n", slot, nr_leaves_on_branch, nr_free + 1, next_slot) | 
| 1610 | pr_devel("after: %lu\n", nr_leaves_on_branch) | 
| 1615 | If nr_free == Number of slots per node - 1 Then | 
| 1618 | Break | 
| 1620 | If assoc_array_ptr_is_meta(ptr) && assoc_array_ptr_is_shortcut(ptr) Then | 
| 1623 | new_s = assoc_array_ptr_to_shortcut(ptr) | 
| 1624 | new_parent = back_pointer | 
| 1625 | slot = parent_slot | 
| 1627 | If Not new_parent Then | 
| 1634 | If assoc_array_ptr_is_shortcut(new_parent) Then | 
| 1636 | s = assoc_array_ptr_to_shortcut(new_parent) | 
| 1639 | pr_devel("excise preceding shortcut\n") | 
| 1641 | new_parent = back_pointer = back_pointer | 
| 1642 | slot = parent_slot = parent_slot | 
| 1644 | If Not new_parent Then | 
| 1652 | back_pointer = new_parent | 
| 1653 | parent_slot = slot | 
| 1654 | new_n = assoc_array_ptr_to_node(new_parent) | 
| 1656 | Go to ascend_old_tree | 
| 1663 | ptr = back_pointer | 
| 1664 | If Not ptr Then Go to gc_complete | 
| 1667 | If assoc_array_ptr_is_shortcut(ptr) Then | 
| 1668 | new_s = assoc_array_ptr_to_shortcut(ptr) | 
| 1669 | new_parent = back_pointer | 
| 1670 | slot = parent_slot | 
| 1672 | If nr_leaves_on_branch <= Number of slots per node Then | 
| 1675 | pr_devel("excise shortcut\n") | 
| 1676 | back_pointer = new_parent | 
| 1677 | parent_slot = slot | 
| 1679 | If Not new_parent Then | 
| 1680 | new_root = assoc_array_node_to_ptr(new_n) | 
| 1681 | Go to gc_complete | 
| 1684 | n = assoc_array_ptr_to_node(new_parent) | 
| 1685 | slots[slot] = assoc_array_node_to_ptr(new_n) | 
| 1687 | Else | 
| 1688 | new_parent = ptr | 
| 1690 | new_n = assoc_array_ptr_to_node(new_parent) | 
| 1692 | ascend_old_tree : | 
| 1693 | ptr = back_pointer | 
| 1694 | If assoc_array_ptr_is_shortcut(ptr) Then | 
| 1695 | shortcut = assoc_array_ptr_to_shortcut(ptr) | 
| 1696 | slot = parent_slot | 
| 1697 | cursor = back_pointer | 
| 1698 | If Not cursor Then Go to gc_complete | 
| 1700 | Else | 
| 1701 | slot = parent_slot | 
| 1705 | node = assoc_array_ptr_to_node(cursor) | 
| 1706 | slot++ | 
| 1707 | Go to continue_node | 
| 1709 | gc_complete : | 
| 1713 | Return 0 | 
| 1715 | enomem : | 
| 1716 | pr_devel("enomem\n") | 
| 1719 | Return -ENOMEM | 
| Source code conversion tool public plug-in interface | X | 
|---|---|
| Support c/c++/esqlc/java Oracle/Informix/Mysql Plug-in can realize: logical Report Code generation and batch code conversion |