void insert_bucket (bucket_s *bucket, u32 x, u32 shift) { switch (bucket->b_type) { case EMPTY: insert_empty(bucket, x, shift); return; case NODE: insert_node(bucket, x, shift); return; case LEAF: insert_leaf(bucket, x, shift); return; default: printf("bad type %ld", bucket->b_type); return; } }
int main() { int choice;//For storing user choice node *start = NULL; //pointer to the first node, which initially points nowhere do { printf("***************************************************************************\n"); printf("\t\tMENUE\n"); printf("****************************************************************************\n"); printf("\t1.Create List\n"); printf("\t2.Display\n"); printf("\t3.Count\n"); printf("\t4.Add to empty list\n"); printf("\t5.Add at beginning\n"); printf("\t6.Add at end\n"); printf("\t7.Add after node\n"); printf("\t8.Add before node\n"); printf("\t9.Delete\n"); printf("\t10.Quit\n\n"); printf("********************************************************************************\n\n"); printf("Enter your choice : "); scanf("%d",&choice); switch(choice) { case 1: create(&start); break; case 2: display(&start); break; case 3: count(&start); break; case 4: insert_empty(&start); break; case 5: insert_beginning(&start); break; case 6: insert_end(&start); break; case 7: insert_after(&start); break; case 8: insert_before(&start); break; case 9: delete_node(&start); break; case 10: break; default: printf("Wrong choice\n"); }/*End of switch */ }while(10!=choice); //End of while free_list(&start); return 0; }//end of main
int mongo_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { struct inode * e; int res; size_t reallen; int32_t realend = size, blk_offset = 0; const off_t write_end = size + offset; char * lock; bson doc, cond; mongo * conn = get_conn(); uint8_t hash[20]; time_t now = time(NULL); e = (struct inode*)fi->fh; if((res = get_cached_inode(path, e)) != 0) return res; if(e->mode & S_IFDIR) return -EISDIR; /* Uncomment this for incredibly slow length calculations. for(;realend >= 0 && buf[realend] == '\0'; realend--); realend++; for(blk_offset = 0; blk_offset < realend && buf[blk_offset] == 0; blk_offset++); blk_offset -= blk_offset > 0 ? 1 : 0; * The code below uses SSE4 instructions to find the first/last * zero bytes by doing 16-byte comparisons at a time. This should give * a ~16 speed boost on blocks with lots of zero bytes over the dumb * method above. */ if(size >= 16) { __m128i zero = _mm_setzero_si128(); lock = (char*)buf + size - 16; while(lock >= buf) { __m128i x = _mm_loadu_si128((__m128i*)lock); res = _mm_movemask_epi8(_mm_cmpeq_epi8(zero, x)); if(res == 0xffff) { lock -= 16; continue; } realend = lock - buf + fls(res ^ 0xffff); break; } if(lock <= buf) realend = 0; lock = (char*)buf; while(lock - buf < realend) { __m128i x = _mm_loadu_si128((__m128i*)lock); res = _mm_movemask_epi8(_mm_cmpeq_epi8(zero, x)); if(res == 0xffff) { lock += 16; continue; } blk_offset = lock - buf + ffs(res ^ 0xffff) - 1; break; } } reallen = realend - blk_offset; if(reallen == 0) { pthread_mutex_lock(&e->wr_lock); res = insert_empty(&e->wr_extent, offset, size); goto end; } #ifdef __APPLE__ CC_SHA1(buf, size, hash); #else SHA1(buf, size, hash); #endif bson_init(&cond); bson_append_binary(&cond, "_id", 0, (char*)hash, sizeof(hash)); bson_finish(&cond); bson_init(&doc); bson_append_start_object(&doc, "$setOnInsert"); char * comp_out = get_compress_buf(); size_t comp_size = snappy_max_compressed_length(reallen); if((res = snappy_compress(buf + blk_offset, reallen, comp_out, &comp_size)) != SNAPPY_OK) { fprintf(stderr, "Error compressing input: %d\n", res); return -EIO; } bson_append_binary(&doc, "data", 0, comp_out, comp_size); bson_append_int(&doc, "offset", blk_offset); bson_append_int(&doc, "size", size); bson_append_time_t(&doc, "created", now); bson_append_finish_object(&doc); bson_finish(&doc); res = mongo_update(conn, blocks_name, &cond, &doc, MONGO_UPDATE_UPSERT, NULL); bson_destroy(&doc); bson_destroy(&cond); if(res != MONGO_OK) { fprintf(stderr, "Error committing block %s\n", conn->lasterrstr); return -EIO; } pthread_mutex_lock(&e->wr_lock); res = insert_hash(&e->wr_extent, offset, size, hash); end: if(write_end > e->size) e->size = write_end; if(now - e->wr_age > 3) { res = serialize_extent(e, e->wr_extent); if(res != 0) { pthread_mutex_unlock(&e->wr_lock); return res; } e->wr_age = now; } pthread_mutex_unlock(&e->wr_lock); if(res != 0) return res; res = update_filesize(e, write_end); if(res != 0) return res; return size; }