static void msd_A(cacheblock_t* cache, size_t N, size_t cache_depth, size_t true_depth) { if (N < 32) { inssort_cache(cache, N, true_depth); return; } if (cache_depth >= CACHED_BYTES) { fill_cache(cache, N, true_depth); cache_depth = 0; } size_t bucketsize[256] = {0}; for (size_t i=0; i < N; ++i) ++bucketsize[cache[i].bytes[cache_depth]]; cacheblock_t* sorted = (cacheblock_t*) malloc(N*sizeof(cacheblock_t)); static size_t bucketindex[256]; bucketindex[0] = 0; for (unsigned i=1; i < 256; ++i) bucketindex[i] = bucketindex[i-1] + bucketsize[i-1]; for (size_t i=0; i < N; ++i) memcpy(&sorted[bucketindex[cache[i].bytes[cache_depth]]++], cache+i, sizeof(cacheblock_t)); memcpy(cache, sorted, N*sizeof(cacheblock_t)); free(sorted); size_t bsum = bucketsize[0]; for (unsigned i=1; i < 256; ++i) { if (bucketsize[i] == 0) continue; msd_A(cache+bsum, bucketsize[i], cache_depth+1, true_depth+1); bsum += bucketsize[i]; } }
/* gets the header "head" from msg. */ static int getheader(void *v, const char *phead, const char ***body) { message_data_t *m = (message_data_t *) v; strarray_t *contents; char *head; *body = NULL; if (!m->cache_full) { fill_cache(m); } /* copy header parameter so we can mangle it */ head = xstrdup(phead); lcase(head); /* check the cache */ contents = (strarray_t *)hash_lookup(head, &m->cache); if (contents) *body = (const char **) contents->data; free(head); if (*body) { return SIEVE_OK; } else { return SIEVE_FAIL; } }
int bgav_bitstream_get_long(bgav_bitstream_t * b, int64_t * ret1, int bits) { int bits_read = 0; int bits_to_copy; int64_t ret = 0; while(bits_read < bits) { if(!b->bit_cache) { if(b->pos >= b->end) return 0; #ifdef OLD_BITSTREAM b->c = *b->pos; b->pos++; b->bit_cache = 8; #else fill_cache(b); #endif } bits_to_copy = bits - bits_read; if(bits_to_copy > b->bit_cache) bits_to_copy = b->bit_cache; ret <<= bits_to_copy; ret |= (b->c >> (b->bit_cache-bits_to_copy)) & (((1<<bits_to_copy)-1)); bits_read += bits_to_copy; b->bit_cache -= bits_to_copy; } *ret1 = ret; return 1; }
int main() { srand(time(0)); generate_box_points(); generate_test_points(); fill_cache(); int p = box_method(); /* double E1 = 0.0; double E2 = 0.0; double EM = 0.0; for (double x = left_x; x <= right_x + 0.00001; x += 0.005) { for (double y = bottom_y; y <= top_y + 0.00001; y += 0.005) { double tmp = fabs(calc(&box_points[p][0], x, y) - solution(x, y)); E1 += tmp; E2 += sqr(tmp); EM = (EM > tmp)?EM:tmp; } }*/ // std::cout << "Problem N\t" << NEURONS << "\t" << POINTS_INNER << "\t" << POINTS_BORDER << "\t" << DELTA << "\t" << cached_values[p] << "\t" << E1 << "\t" << E2 << "\t" << EM << std::endl; std::cout << "RBF-PLATE" << std::endl; for (int i=0; i < NEURONS; ++i) { std::cout << box_points[p][i * 3] << " " << box_points[p][i * 3 + 1] << " " << box_points[p][i * 3 + 2]; std::cout << std::endl; } return 0; }
void msd_A_adaptive(unsigned char** strings, size_t N) { cacheblock_t* cache = (cacheblock_t*) malloc(N*sizeof(cacheblock_t)); for (size_t i=0; i < N; ++i) cache[i].ptr = strings[i]; fill_cache(cache, N, 0); msd_A_adaptive(cache, N, 0, 0); for (size_t i=0; i < N; ++i) strings[i] = cache[i].ptr; free(cache); }
static int get_frame( hnd_t handle, cli_pic_t *output, int frame ) { cache_hnd_t *h = handle; FAIL_IF_ERR( frame < h->first_frame, NAME, "frame %d is before first cached frame %d \n", frame, h->first_frame ); fill_cache( h, frame ); if( frame > LAST_FRAME ) /* eof */ return -1; int idx = frame - (h->eof ? h->eof - h->max_size : h->first_frame); *output = *h->cache[idx]; return 0; }
static void msd_A_lsd_adaptive(unsigned char** strings, size_t N) { Cacheblock<CachedChars>* cache = static_cast<Cacheblock<CachedChars>*>( malloc(N*sizeof(Cacheblock<CachedChars>))); for (size_t i=0; i < N; ++i) cache[i].ptr = strings[i]; fill_cache(cache, N, 0); msd_lsd_adaptive(cache, N, 0); for (size_t i=0; i < N; ++i) strings[i] = cache[i].ptr; free(cache); }
int llp_nodes_initialize() { nodes.cache_size = llp_get_cache_size(); /* Allocating memory and clearing nodes cache. */ nodes.cache_list = (node_t *)malloc((MAX_ACTIVE_NODES + nodes.cache_size) * sizeof(node_t)); if (nodes.cache_list == NULL) { liblog_fatal(LAYER_LINK, "error in malloc: %s.", strerror(errno)); return LLP_ERROR; } nodes.cached = 0; nodes.active = 0; /* Initializing mutexes. */ if (pthread_mutex_init(&nodes_mutex, NULL) > 0) { liblog_error(LAYER_LINK, "error allocating nodes mutex: %s.", strerror(errno)); return LLP_ERROR; } liblog_debug(LAYER_LINK, "mutex initialized."); /* Fill the cache. */ if (fill_cache(llp_get_static_nodes_file()) == LLP_ERROR) { liblog_error(LAYER_LINK, "error getting nodes from static nodes file."); } if (fill_cache(llp_get_recent_nodes_file()) == LLP_ERROR) { liblog_error(LAYER_LINK, "error getting nodes from recent nodes file."); } if (nodes.cached == 0) { liblog_error(LAYER_LINK, "error filling nodes cache, cache empty."); } /* Clearing active hosts table. */ memset(nodes.active_list, 0, sizeof(nodes.active_list)); liblog_debug(LAYER_LINK, "nodes module initialized."); return LLP_OK; }
void msd_A2_adaptive(unsigned char** strings, size_t N) { cacheblock_t* cache = static_cast<cacheblock_t*>(malloc(N*sizeof(cacheblock_t))); for (size_t i=0; i < N; ++i) cache[i].ptr = strings[i]; TempSpace tmp(strings, N); fill_cache(cache, N, 0); msd_A2_adaptive(cache, N, 0, 0, tmp); for (size_t i=0; i < N; ++i) strings[i] = cache[i].ptr; free(cache); }
void bgav_bitstream_init(bgav_bitstream_t * b, const uint8_t * pos, int len) { b->pos = pos; b->end = pos + len; #ifdef OLD_BITSTREAM b->c = *pos; b->pos++; b->bit_cache = 8; #else fill_cache(b); #endif }
static void msd_lsd_adaptive(Cacheblock<CachedChars>* cache, size_t N, size_t depth) { BOOST_STATIC_ASSERT(CachedChars%2==0); BOOST_STATIC_ASSERT(CachedChars>=2); if (N < 0x10000) { msd_lsd(cache, N, depth); return; } fill_cache(cache, N, depth); for (int byte=CachedChars-1; byte > 0; byte -= 2) { size_t bucketsize[0x10000] = {0}; for (size_t i=0; i < N; ++i) { uint16_t bucket = (cache[i].chars[byte-1] << 8) | cache[i].chars[byte]; ++bucketsize[bucket]; } Cacheblock<CachedChars>* sorted = (Cacheblock<CachedChars>*) malloc(N*sizeof(Cacheblock<CachedChars>)); static size_t bucketindex[0x10000]; bucketindex[0] = 0; for (size_t i=1; i < 0x10000; ++i) bucketindex[i] = bucketindex[i-1] + bucketsize[i-1]; for (size_t i=0; i < N; ++i) { uint16_t bucket = (cache[i].chars[byte-1] << 8) | cache[i].chars[byte]; memcpy(&sorted[bucketindex[bucket]++], cache+i, sizeof(Cacheblock<CachedChars>)); } memcpy(cache, sorted, N*sizeof(Cacheblock<CachedChars>)); free(sorted); } size_t start=0, cnt=1; for (size_t i=0; i < N-1; ++i) { if (memcmp(cache[i].chars.data(), cache[i+1].chars.data(), CachedChars) == 0) { ++cnt; continue; } if (cnt > 1 && cache[start].chars[CachedChars-1] != 0) { msd_lsd_adaptive(cache+start, cnt, depth+CachedChars); } cnt = 1; start = i+1; } if (cnt > 1 && cache[start].chars[CachedChars-1] != 0) { msd_lsd_adaptive(cache+start, cnt, depth+CachedChars); } }
static void msd_A2_adaptive(cacheblock_t* cache, size_t N, size_t cache_depth, size_t true_depth, TempSpace& tmp) { if (N < 0x10000) { msd_A2(cache, N, cache_depth, true_depth, tmp); return; } if (cache_depth >= CACHED_BYTES) { fill_cache(cache, N, true_depth); cache_depth = 0; } tmp.allocate(N); size_t* bucketsize = static_cast<size_t*>(calloc(0x10000, sizeof(size_t))); for (size_t i=0; i < N; ++i) { uint16_t bucket = (cache[i].bytes[cache_depth] << 8) | cache[i].bytes[cache_depth+1]; ++bucketsize[bucket]; } static boost::array<size_t, 0x10000> bucketindex; bucketindex[0] = 0; for (unsigned i=1; i < 0x10000; ++i) bucketindex[i] = bucketindex[i-1] + bucketsize[i-1]; for (size_t i=0; i < N; ++i) { uint16_t bucket = (cache[i].bytes[cache_depth] << 8) | cache[i].bytes[cache_depth+1]; tmp[bucketindex[bucket]++] = cache[i]; } copy(tmp, cache, N); tmp.free(); size_t bsum = bucketsize[0]; for (unsigned i=1; i < 0x10000; ++i) { if (bucketsize[i] == 0) continue; if (i & 0xFF) msd_A2_adaptive(cache+bsum, bucketsize[i], cache_depth+2, true_depth+2, tmp); bsum += bucketsize[i]; } free(bucketsize); }
static void msd_A_adaptive(cacheblock_t* cache, size_t N, size_t cache_depth, size_t true_depth) { if (N < 0x10000) { msd_A(cache, N, cache_depth, true_depth); return; } if (cache_depth >= CACHED_BYTES) { fill_cache(cache, N, true_depth); cache_depth = 0; } size_t* bucketsize = (size_t*) calloc(0x10000, sizeof(size_t)); for (size_t i=0; i < N; ++i) { uint16_t bucket = (cache[i].bytes[cache_depth] << 8) | cache[i].bytes[cache_depth+1]; ++bucketsize[bucket]; } cacheblock_t* sorted = (cacheblock_t*) malloc(N*sizeof(cacheblock_t)); static size_t bucketindex[0x10000]; bucketindex[0] = 0; for (unsigned i=1; i < 0x10000; ++i) bucketindex[i] = bucketindex[i-1] + bucketsize[i-1]; for (size_t i=0; i < N; ++i) { uint16_t bucket = (cache[i].bytes[cache_depth] << 8) | cache[i].bytes[cache_depth+1]; memcpy(&sorted[bucketindex[bucket]++], cache+i, sizeof(cacheblock_t)); } memcpy(cache, sorted, N*sizeof(cacheblock_t)); free(sorted); size_t bsum = bucketsize[0]; for (unsigned i=1; i < 0x10000; ++i) { if (bucketsize[i] == 0) continue; if (i & 0xFF) msd_A_adaptive(cache+bsum, bucketsize[i], cache_depth+2, true_depth+2); bsum += bucketsize[i]; } free(bucketsize); }
static void msd_lsd(Cacheblock<CachedChars>* cache, size_t N, size_t depth) { BOOST_STATIC_ASSERT(CachedChars>=1); if (N < 32) { insertion_sort(cache, N, depth); return; } fill_cache(cache, N, depth); for (int byte=CachedChars-1; byte >= 0; --byte) { size_t bucketsize[256] = {0}; for (size_t i=0; i < N; ++i) ++bucketsize[cache[i].chars[byte]]; Cacheblock<CachedChars>* sorted = (Cacheblock<CachedChars>*) malloc(N*sizeof(Cacheblock<CachedChars>)); size_t bucketindex[256]; bucketindex[0] = 0; for (size_t i=1; i < 256; ++i) bucketindex[i] = bucketindex[i-1] + bucketsize[i-1]; for (size_t i=0; i < N; ++i) memcpy(&sorted[bucketindex[cache[i].chars[byte]]++], cache+i, sizeof(Cacheblock<CachedChars>)); memcpy(cache, sorted, N*sizeof(Cacheblock<CachedChars>)); free(sorted); } size_t start=0, cnt=1; for (size_t i=0; i < N-1; ++i) { if (memcmp(cache[i].chars.data(), cache[i+1].chars.data(), CachedChars) == 0) { ++cnt; continue; } if (cnt > 1 && cache[start].chars[CachedChars-1] != 0) { msd_lsd(cache+start, cnt, depth+CachedChars); } cnt = 1; start = i+1; } if (cnt > 1 && cache[start].chars[CachedChars-1] != 0) { msd_lsd(cache+start, cnt, depth+CachedChars); } }
bool cps_api_get_handle(cps_api_key_t &key, cps_api_channel_t &handle) { if (cache_connect(key,handle)) { return true; } cps_api_object_owner_reg_t owner; if (!cps_api_find_owners(&key,owner)) return false; bool rc = (cps_api_connect_owner(&owner, handle))==cps_api_ret_code_OK; if (!rc) { char buff[SCRATCH_LOG_BUFF]; EV_LOG(ERR,DSAPI,0,"NS","Could not connect with owner for %s (%s)", cps_api_key_print(&key,buff,sizeof(buff)-1), owner.addr.addr_type== e_std_socket_a_t_STRING ? owner.addr.address.str: "unk"); } if (rc) { fill_cache(&key,owner); } return rc; }
std::streamsize NoSeekFile::read(void *dst, std::streamsize bytes) { #ifdef GNASH_NOSEEK_FD_VERBOSE std::cerr << boost::format("read_cache(%d) called") % bytes << std::endl; #endif if (eof()) { #ifdef GNASH_NOSEEK_FD_VERBOSE std::cerr << "read_cache: at eof!" << std::endl; #endif return 0; } fill_cache(bytes + tell()); #ifdef GNASH_NOSEEK_FD_VERBOSE printInfo(); #endif std::streamsize ret = std::fread(dst, 1, bytes, _cache); if (ret == 0) { if (std::ferror(_cache)) { std::cerr << "an error occurred while reading from cache" << std::endl; } #if GNASH_NOSEEK_FD_VERBOSE if (std::feof(_cache)) { std::cerr << "EOF reached while reading from cache" << std::endl; } #endif } #ifdef GNASH_NOSEEK_FD_VERBOSE std::cerr << boost::format("fread from _cache returned %d") % ret << std::endl; #endif return ret; }
bool NoSeekFile::seek(std::streampos pos) { #ifdef GNASH_NOSEEK_FD_WARN_SEEKSBACK if (pos < tell()) { std::cerr << boost::format("Warning: seek backward requested " "(%ld from %ld)") % pos % tell() << std::endl; } #endif fill_cache(pos); if (std::fseek(_cache, pos, SEEK_SET) == -1) { std::cerr << "Warning: fseek failed" << std::endl; return false; } return true; }
static void msd_A2(cacheblock_t* cache, size_t N, size_t cache_depth, size_t true_depth, TempSpace& tmp) { if (N < 32) { inssort_cache(cache, N, true_depth); return; } if (cache_depth >= CACHED_BYTES) { fill_cache(cache, N, true_depth); cache_depth = 0; } boost::array<size_t, 256> bucketsize; bucketsize.assign(0); for (size_t i=0; i < N; ++i) ++bucketsize[cache[i].bytes[cache_depth]]; tmp.allocate(N); static boost::array<size_t, 256> bucketindex; bucketindex[0] = 0; for (unsigned i=1; i < 256; ++i) bucketindex[i] = bucketindex[i-1] + bucketsize[i-1]; for (size_t i=0; i < N; ++i) tmp[bucketindex[cache[i].bytes[cache_depth]]++] = cache[i]; copy(tmp, cache, N); tmp.free(); size_t bsum = bucketsize[0]; for (unsigned i=1; i < 256; ++i) { if (bucketsize[i] == 0) continue; msd_A2(cache+bsum, bucketsize[i], cache_depth+1, true_depth+1, tmp); bsum += bucketsize[i]; } }
static void multikey_cache(Cacheblock<CachedChars>* cache, size_t N, size_t depth) { if (N < 32) { if (N==0) return; if (CacheDirty) { insertion_sort(cache, N, depth); return; } inssort_cache_block(cache, N); size_t start=0, cnt=1; for (size_t i=0; i < N-1; ++i) { if (Cmp()(cache[i], cache[i+1]) == 0) { ++cnt; continue; } if (cnt > 1 and cache[start].cached_bytes & 0xFF) insertion_sort(cache+start, cnt, depth+CachedChars); cnt = 1; start = i+1; } if (cnt > 1 and cache[start].cached_bytes & 0xFF) insertion_sort(cache+start, cnt, depth+CachedChars); return; } if (CacheDirty) { fill_cache(cache, N, depth); } // Move pivot to first position to avoid wrapping the unsigned values // we are using in the main loop from zero to max. std::swap(cache[0], med3char( med3char(cache[0], cache[N/8], cache[N/4], Cmp()), med3char(cache[N/2-N/8], cache[N/2], cache[N/2+N/8],Cmp()), med3char(cache[N-1-N/4], cache[N-1-N/8], cache[N-3], Cmp()), Cmp())); Cacheblock<CachedChars> partval = cache[0]; size_t first = 1; size_t last = N-1; size_t beg_ins = 1; size_t end_ins = N-1; while (true) { while (first <= last) { const int res = Cmp()(cache[first], partval); if (res > 0) { break; } else if (res == 0) { std::swap(cache[beg_ins++], cache[first]); } ++first; } while (first <= last) { const int res = Cmp()(cache[last], partval); if (res < 0) { break; } else if (res == 0) { std::swap(cache[end_ins--], cache[last]); } --last; } if (first > last) break; std::swap(cache[first], cache[last]); ++first; --last; } // Some calculations to make the code more readable. const size_t num_eq_beg = beg_ins; const size_t num_eq_end = N-1-end_ins; const size_t num_eq = num_eq_beg+num_eq_end; const size_t num_lt = first-beg_ins; const size_t num_gt = end_ins-last; // Swap the equal pointers from the beginning to proper position. const size_t size1 = std::min(num_eq_beg, num_lt); std::swap_ranges(cache, cache+size1, cache+first-size1); // Swap the equal pointers from the end to proper position. const size_t size2 = std::min(num_eq_end, num_gt); std::swap_ranges(cache+first, cache+first+size2, cache+N-size2); // Now recurse. multikey_cache<CachedChars, false>(cache, num_lt, depth); multikey_cache<CachedChars, false>(cache+num_lt+num_eq, num_gt, depth); if (partval.cached_bytes & 0xFF) multikey_cache<CachedChars, true>( cache+num_lt, num_eq, depth+CachedChars); }
/* * Machinery for searching for PCI devices. * * This is a general function to support all possible * search filtering conditions. */ int sharedDevPCIFindCB( const epicsPCIID *idlist, devPCISearchFn searchfn, void *arg, unsigned int opt /* always 0 */ ) { int err=0; ELLNODE *cur; osdPCIDevice *curdev=NULL; const epicsPCIID *search; if(!searchfn || !idlist) return S_dev_badArgument; if(epicsMutexLock(sharedGuard)!=epicsMutexLockOK) return S_dev_internal; /* * Ensure all entries for the requested device/vendor pairs * are in the 'devices' list. */ for(search=idlist; search->device!=DEVPCI_LAST_DEVICE; search++){ if(search->device==DEVPCI_ANY_DEVICE || search->vendor==DEVPCI_ANY_VENDOR) { errlogPrintf("devPCI: Wildcards are not supported in Device and Vendor fields\n"); err=S_dev_badRequest; goto done; } if( (err=fill_cache(search->device, search->vendor)) ) goto done; } cur=ellFirst(&devices); for(; cur; cur=ellNext(cur)){ curdev=CONTAINER(cur,osdPCIDevice,node); for(search=idlist; search && !!search->device; search++){ if(search->device!=curdev->dev.id.device) continue; else if(search->vendor!=curdev->dev.id.vendor) continue; else if( search->sub_device!=DEVPCI_ANY_SUBDEVICE && search->sub_device!=curdev->dev.id.sub_device ) continue; else if( search->sub_vendor!=DEVPCI_ANY_SUBVENDOR && search->sub_vendor!=curdev->dev.id.sub_vendor ) continue; else if( search->pci_class!=DEVPCI_ANY_CLASS && search->pci_class!=curdev->dev.id.pci_class ) continue; else if( search->revision!=DEVPCI_ANY_REVISION && search->revision!=curdev->dev.id.revision ) continue; /* Match found */ err=searchfn(arg,&curdev->dev); switch(err){ case 0: /* Continue search */ break; case 1: /* Abort search OK */ err=0; default:/* Abort search Err */ goto done; } } } err=0; done: epicsMutexUnlock(sharedGuard); return err; }