Ejemplo n.º 1
0
        public async Task <BTreeListResponseDTO> CreateBTreeFromListAsync(BTreeListRequestDTO listDTO)
        {
            if (listDTO.List.Count == 0)
            {
                throw new ArgumentNullException("Numbers must be a list of integers");
            }

            BTree binaryTree = new BTree();

            binaryTree.AddNodesFromList(listDTO.List);

            await _binaryTreeRepository.SaveBTreeAsync(binaryTree);

            BTreeListResponseDTO response = new BTreeListResponseDTO();

            response.UUID = binaryTree.UUID;

            return(response);
        }
Ejemplo n.º 2
0
        public async Task <BTree> GetBTreeAsync(string uuid)
        {
            string concatTreeNodeList = await _redisCache.GetStringAsync(uuid);

            if (concatTreeNodeList == null)
            {
                throw new NullReferenceException($"Binary tree with uuid '{uuid}' not found!");
            }

            BTree      binaryTree   = new BTree(uuid);
            List <int> treeNodeList = new List <int>(Array.ConvertAll(concatTreeNodeList.Split(NODE_LIST_STR_SEPARATOR), int.Parse));

            binaryTree.AddNodesFromList(treeNodeList);

            treeNodeList       = null;
            concatTreeNodeList = null;

            return(binaryTree);
        }